int getchar (void);
The GetChar function is equivalent to GETC (stdin). Read one character from standard input
int getc (FILE *stream);
Return value: The return value is usigned char but we treat it with the int type
is typically defined as a macro to use
int fgetc (FILE *stream);
Is the same as the GETC function, but is generally defined as function usage
Macros and Functions:
Macro does not occupy the scheduling time, only takes up the compilation time;
The function occupies the scheduling time, does not occupy the compile time;
is equivalent to PUTC (c, stdout).
Output point to standard output
int FPUTC (int c, FILE *stream);
Output to the specified stream file
Example 1: File copy
/*./mycpy src dest*//*function, using FPUTC fgetc to implement file copy function*//*argv[1]:src argv[2]:d est*/#include<stdio.h>#include<stdlib.h>intMainintARGC,Char**argv) {FILE*fps; FILE*FPD; intch; if(ARGC <3) {fprintf (stderr,"usage:%s <src.file> <dest.file>\n", argv[0]); Exit (1); } //Open Sourcefps = fopen (argv[1],"R"); if(fps = =NULL) {Perror ("fopen ()"); Exit (1); } //Open Target StreamFPD = fopen (argv[2],"w+"); if(FPD = =NULL) {Perror ("fopen ()"); Fclose (fps);//when the target stream fails to open, the source will be closedExit1); } while(1) {ch=fgetc (fps); if(ch = = EOF)//If you read the end of the file or read an error Break; FPUTC (CH,FPD); } fclose (FPD); Fclose (fps); Exit (0);}
Example two: Calculating the size of a file (fgetc FPUTC use)
/*calculate the size of a file*/#include<stdio.h>#include<stdlib.h>intMainintARGC,Char**argv) {FILE*FP; intCH =0 ; intCount =0 ; if(ARGC <2) {fprintf (stderr,"usage:....\n"); Exit (1); } FP= fopen (argv[1],"R"); if(fp = =NULL) {Perror ("fopen ()"); Exit (1); } while(1) {ch=fgetc (FP); if(ch = =EOF) Break; Count++; } fprintf (stdout,"count =%d\n", Count); Fclose (FP); Exit (1);}
The next day-------Fgetc,fputc,fgets,gputs,fread,fwrite