I'm testing the usage of fprintf()
and it is not working. When I first wrote the code I forgot to add \n
inside fprintf()
and it worked. However, when I added \n
at the start of "test 1 2" it stopped working.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
FILE* f = fopen("test.txt", "r+");
if( f == NULL) return 0;
char str[4][10];
for(int a = 0; a <= 3; ++a)
{
fscanf(f, " %[^\t\n]s", str[a]);
printf("%s\n", str[a]);
}
fprintf(f, "\ntest 1 2\n");
fclose(f);
system("pause");
return 0;
}
and my test.txt contains ( instead of \t
and \n
I pressed tab and enter in the file but I couldn't manage it here)
a b\t c d\t e\n f g