// fgetc_fputc.c #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { FILE *fp0 = (FILE *)NULL, *fp1 = (FILE *)NULL; char cKey = '\0'; fp0 = fopen("GET.TXT", "r"); if (fp0 == NULL) { fclose(fp0); exit(EXIT_FAILURE); } fp1 = fopen("PUT.TXT", "w+"); if (fp1 == NULL) { fclose(fp1); exit(EXIT_FAILURE); } while((cKey = fgetc(fp0)) != EOF) fputc(cKey, fp1); fclose(fp0); fclose(fp1); exit(EXIT_SUCCESS); }fgetc(), fputc()和fgets(), fputs()的差異在它是以字元 (sizeof(char))為單位,來對檔案做讀取寫入的動作,所以它就沒有換行字元 ('\n')的概念....
函式原型:
int fgetc(FILE *stream);
int fputc(int c, FILE *stream);
沒有留言:
張貼留言