調用fputs函數,把10個字符串輸出到文件中,再從此文件中讀入這10個字符串放在一個字符串數組中;最后把字符串數組中的字符串輸出到終端屏幕。


源程序:

#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
char s[100];
FILE *fp;
if((fp=fopen("e:\\file.txt","w+"))==NULL)
{
printf("can't open this file.\n");
exit(0);
}
for(i=0;i<5;i++)
{
gets(s);
fputs(s,fp);
fprintf(fp,"\n");
}

rewind(fp); //將文件指針指回到文件開始的地方

for(i=0;i<5;i++)
{
fgets(s,100,fp);
printf("%s",s);
}

fclose(fp);
return 1;
}

運行結果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM