Inserting "#" before read if file is indented.
int main()
{
bool found = false;
char fileOrig[MAX_PATH] = "F:\\Test\\test.txt";
char fileRepl[MAX_PATH] = "F:\\Test\\myReplacedFile.txt";
const char text2find[80] = "READ ";
const char text3find[80] = "\n";
char text4find[80] = ".";
const char text2repl[80] = "# READ ";
const char text3repl[80] = "#";
char buffer[MAX_LEN_SINGLE_LINE+2];
char buffer1[MAX_LEN_SINGLE_LINE+2];
char buffer2[MAX_LEN_SINGLE_LINE+2];
char *buff_ptr, *find_ptr;
FILE *fp1, *fp2,*fp3;
size_t find_len = strlen(text2find);
fp1 = fopen(fileOrig,"r+");
fp2 = fopen(fileRepl,"w+");
int i=0;
char *p, *q;
char line[80];
int c = '.';
int result;
while(fgets(buffer,MAX_LEN_SINGLE_LINE+2,fp1))
{
buff_ptr = buffer;
strcpy(buffer2,buffer);
i = 0;
while( i++ < strlen(buffer))
{
if(isspace(buffer[i]))
continue;
strcpy(buffer2,&(buffer[i]));
break;
}
if(strncmp(buffer2,"READ",4) == 0)
{
found = true;
sprintf(buffer1,"# %s",buffer);
fputs(buffer1,fp2);
}
else if(found == false)
{
fputs(buffer,fp2);
}
else
{
sprintf(buffer1,"# %s",buffer);
fputs(buffer1,fp2);
if(strstr(buffer,".") != NULL)
found = false;
}
}
fclose(fp2);
fclose(fp1);
return 0;
}