I need to write a character at the end of each line of the file. So how, after recording, go to the next line of the file?
Answer 1, authority 100%
In general, something like this is easiest:
# include & lt; stdlib.h & gt;
#include & lt; stdio.h & gt;
int main ()
{
FILE * in = fopen ("data", "r");
FILE * out = fopen ("data ~", "w");
if (in == NULL || out == NULL)
{
fprintf (stderr, "Error open file \ n");
return 1;
}
char addSym = '$';
int c;
while ((c = fgetc (in))! = EOF)
{
if (c == '\ n') fputc (addSym, out);
fputc (c, out);
}
fclose (in);
fclose (out);
unlink ("data");
rename ("data ~", "data");
}
Answer 2
If the text file already exists, then you read line by line by making a riplace "\ r \ n"
to "{desired text} \ r \ n"
and then save the text.
Everyone.