fputc、fgetc和putc、getc同为对文件读写的操作函数,他们之间有何不同,具体用法是什么?是不是对象是不是文件的区别?
int fputc(int c, FILE *stream);
fputc() writes the character c, cast to an unsigned char, to stream.
int putc(int c, FILE *stream);
putc() is equivalent to fputc() except that it may be implemented as a
macro which evaluates stream more than once.
int fgetc(FILE *stream);
fgetc() reads the next character from stream and returns it as an
unsigned char cast to an int, or EOF on end of file or error.
int getc(FILE *stream);
getc() is equivalent to fgetc() except that it may be implemented as a
macro which evaluates stream more than once.
为了书写方便,系统把fputc和fgetc定义为宏名putc和getc:
#define putc(ch, fp) fputc(ch, fp)
#define getc(fp) fgetc(fp)
这个是在stdio.h中定义的,所以没有区别。