本程序由Turbo C2.0編譯通過。文本文件1.txt請放在Turbo C所在目錄下。則輸出文件1.txt也在Turbo C所在目錄下。
*/
#include "stdio.h"
main()
{
FILE *fp,*temp;
char ch;
int i=0;
clrscr();
if(((fp=fopen("1.txt","r+"))&&(temp=fopen("1.tmp","w+")))==NULL)
{
printf("Can't open file\n");
printf("Press any key to exit...");
getch();
exit(0);
}
printf("\nPlease wait...");
while(!feof(fp))
{
fputc(fgetc(fp),temp);
i++;
if(i%200==0) fputc('\n',temp);
}
rewind(temp);
fputc('\n',fp);
fputc('\n',fp);
while(!feof(temp)) fputc(fgetc(temp),fp);
fopen("1.tmp","w");
fclose(fp);
fclose(temp);
printf("OK!\n");
printf("Press any key to exit...");
getch();
printf("Bye bye!");
exit(0);
}
附:讀取文本文件
cha dat[20];
FILE *fp;
fp=fopen("man.txt","rb");
fread(dat, sizeof(char), 20, fp);
int a=strchr(dat,'@');