我有一个名为 test.txt 的文件。我想从文件中逐个字符地读取。然后从“开始”开始写到“停止”一个新文件,它的名字是main.txt。我试图编码,但它没有运行。请帮我。
#include<stdio.h>
//#include<conio.h>
FILE *fpR, *fpW;
char RFile[25],WFile[25],stArt[5],stOp[4],swA[5],swO[4];
char *c;
int cc=0,i=0;
// clrscr();
//Readin file's open process
printf("Please! Enter the name of the file to be read : \n");
scanf("%s",RFile);
//Writing file's open process
printf("Please! Enter the name of the file to be write : \n");
scanf("%s",WFile);
//Openin files
fpR = fopen(RFile,"r");
if (fpR==NULL) {
printf("Could not open %s!\n",RFile);
return 1;
}
fpW = fopen(WFile,"w");
if (fpW==NULL) {
printf("Could not open %s!\n",WFile);
return 1;
}
do {
for(i = 1;i <= 5;i++) {
swA[i] = fgetc(fpR);
if (swA=="start"){
fprintf(fpW,"%s",swA);
fprintf(stdout,"%s",swA);
}
for(i = 1;i <= 4;i++) {
swO[i] = fgetc(fpR);
if (swO=="stop"){
break;
}
}while (c != EOF);
// Close files
fclose(fpR);
fclose(fpW);
// getch();
return 0;
}
测试.txt
testfileisitozetoPıorkgldstartfldsfslf
1lsfslHkf12e43Y54465kds2cmSb3cmb4 op3I3533
5cmkr3rCdqe22e43S5446T5ztop5U6l271Rlr2l83KlccSck49
kr3rdWqe2I2e4354N465Sop33E533tC
VtteEe5R56l271Tlr2l83IlcMcSck4E9stopCCCINCISIweklemfkfKER
主文件
fldsfslf
1lsfslHkf12e43Y54465kds2cmSb3cmb4 op3I3533
5cmkr3rCdqe22e43S5446T5ztop5U6l271Rlr2l83KlccSck49
kr3rdWqe2I2e4354N465Sop33E533tC
VtteEe5R56l271Tlr2l83IlcMcSck4E9