源程式:
//把從鍵盤輸入的文本按原樣輸出到名為file_a.txt的檔案中,用字元@作為鍵盤輸入
//結束的标志
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fpout;
char ch;
if((fpout=fopen("e:\\file_a.txt","w"))==NULL)
{
printf("can't open this file!\n");
exit(0);
}
ch=getchar();
while(ch!='@')
{
fputc(ch,fpout);
ch=getchar();
}
fclose(fpout);
return 1;
}
運作結果: