I have a file whose name is test.txt. I want to read character by character from the file. Then start writing from "start" to "stop" a new file, its name is main.txt. I tried to code, however it did not run. Please help me.
#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;
}
test.txt
testfileisitozetoPıorkgldstartfldsfslf
1lsfslHkf12e43Y54465kds2cmSb3cmb4 op3I3533
5cmkr3rCdqe22e43S5446T5ztop5U6l271Rlr2l83KlccSck49
kr3rdWqe2I2e4354N465Sop33E533tC
VtteEe5R56l271Tlr2l83IlcMcSck4E9stopCCCINCISIweklemfkfKER
main.txt
fldsfslf
1lsfslHkf12e43Y54465kds2cmSb3cmb4 op3I3533
5cmkr3rCdqe22e43S5446T5ztop5U6l271Rlr2l83KlccSck49
kr3rdWqe2I2e4354N465Sop33E533tC
VtteEe5R56l271Tlr2l83IlcMcSck4E9