Code:
char buffer[MAX_LEN_SINGLE_LINE+2];
char *buff_ptr, *find_ptr,*find_ptr2,*quit1,*quit2,*find_ptr3,*find_ptr4,*find_ptr5,*find_ptr6,*find_ptr7,*find_ptr8;
const char text2find1[80] = "NW";
const char text2repl1[80] = "NWELL";
const char text2find[80] = "V";
const char text2repl[80] = "VIA";
const char text2finda[80] = "DM1";
const char text2repla[80] = "M1DMY";
size_t find_len1 = strlen(text2find1);
size_t find_len2 = strlen(text2find);
size_t find_len3 = strlen(text2finda);
while(fgets(buffer,MAX_LEN_SINGLE_LINE+2,oldf))
{
buff_ptr = buffer;
quit1 = strstr(buff_ptr,"DNW");
quit2 = strstr(buff_ptr,"DMN2V");
char *quit3=strstr(buff_ptr,"DMP2V");
if(quit1==NULL&&quit2==NULL&&quit3==NULL)
{
while ((find_ptr = strstr(buff_ptr,text2find1)))
{
while(buff_ptr < find_ptr)
fputc((int)*buff_ptr++,newf);
fputs(text2repl1,newf);
buff_ptr += find_len1;
}
while ((find_ptr2 = strstr(buff_ptr,text2find)))
{
while(buff_ptr < find_ptr2)
fputc((int)*buff_ptr++,newf);
fputs(text2repl,newf);
buff_ptr += find_len2;
}
while ((find_ptr3 = strstr(buff_ptr,text2finda)))
{
while(buff_ptr < find_ptr3)
fputc((int)*buff_ptr++,newf);
fputs(text2repla,newf);
buff_ptr += find_len3;
}
}fputs(buff_ptr,newf);
}
Hello Guys
I am a novice and I require you guys to help me to conver this into a general function so that when I put replace("a","b") in the main it is done instead of the repetition of the steps as you see.
Please help me.