I need to read in table of data in a format x*[tab]*y*[tab]*z*[tab]\n*
so I am using fopen
and fgetc
to stream characters. Loop is ending when c==EOF
. (c
is character.)
But I had difficulties with that as it overflows my array. After doing some debugging I realised that the opened file after the last line contains:
Northampton Oxford 68 ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[...]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýý««««««««îþîþ
What is that? And why does that not appear in my plain text file? And how do I overcome this problem?
destination = fopen("ukcities.txt", "rt"); // r = read, t=text
if (destination != NULL) {
do {
c = fgetc (destination);
if (c == ' ') {
temp_input[i][n] = '\0';
i++;
n=0;
} else if (c == '\n') {
temp_input[i][n] = '\0';
printf("%s %s %s \n", temp_input[0], temp_input[1], temp_input[2]);
i = 0;
n=0;
} else {
temp_input[i][n] = c;
n++;
}
} while (c != -1);
return 1;
} else {
return 0;
}