Hello fellow programmers. I have little problem. I cannot figure out how to open files with different numbers (in the filename) going from 1 to whatever number of files exist.
For example, I have two (or eventually n) files named game_1.txt
and game_2.txt
. This loop should open these two files (or eventually all with this pattern, in that folder).
I am getting errors, namely:
passing argument 2 of 'fopen' makes pointer from integer without a cast.
Here is what I have:
main()
{
FILE *fr;
int i=1;
char b;
while(fr=fopen("game_%d.txt",i) != NULL)
{
while(fscanf(fr,"%c",&b) > 0)
{
printf("%c",b);
}
i++;
}
return 0;
}