Just to cut short, the program is supposed to read from a file with formatted as "int string", e.g. "5 Liverpool (new line)2 Manchester" and print the content on screen. The problem occurs on the 4th (out of 5) iteration and the program just crashes. I suppose the better way would include using functions such as gets, however, this is for a entry level class in C, so I'm pretty sure those functions have not been covered by the curriculum. Before you look into it, I've used the same principle with fscanf on another problem, and it worked flawlessly (but the file was formatted as "string int"). Any help would be much appreciated. Thanks.
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *dat;
FILE *dat1;
dat = fopen("ekipe.txt", "r");
int ek[5], bd[5], i = 0, t1, t2, g1, g2;
char im[5][10];
for(i = 0; i < 5; i++)
bd[i] = 0;
if(dat)
while(!feof(dat))
{
fscanf(dat, "%d %s\n", &ek[i], &im[i]);
printf("%d %s\n", ek[i], im[i]);
i++;
}
fclose(dat);
system("PAUSE");
return 0;
}