hi again, i am having some dificulties replacing a certain line of a file.My problem in specific is writing to the file, a certain string, overwriting the line i want. However, my program just writes to the end of file ( as it should, according to the code ).
I will give you the code, along with examples:
the line i want to replaceCode:im man this strinks
i want to replace with chars ' 'Code:this stinks
my program, if he detects a certain string in the line, it is supposed to replace the line with chars ' ', if(name_esq == this), then replace the line that has this, like so:
however. it will do:Code:im man
this is an excert of the program:Code:im man this stinks
any sugestions will be gratefully accepted.PHP Code:
FILE * def
while(fgets(line2, MAXLINE , def))
/* line2 - line of file def*/
printf("anything\n"); /* for debugging */
if(strstr(line2,name_esq)) /* if name_esq is in line2*/
printf("if works\n");/* for debugging */
printf("%s\n", line2); /* for debugging */
for(k=0; line2[k]!= '\n';k++)
/*replaces line2's chars with ' '
}/* I expect to replace the line in def,
which has the occurence of name_esq
but instead, it writes to the next line
as in the example.
P.S. : if you think i overexplained, please warn me and i will try to rearrange it.
Thanks in advance