This is a really fascinating error to me, because literally an hour ago this code was working just fine, but now it's not.
Essentially what is happening is that the first character of first 'block' of the following row is being appended as the last character of the final 'block'
Whereby 'block' I mean the string that is held within that row/col.
For example, let's say that the array is supposed to be something like
1,2,3,Hello
4,5,6,Wonder
It is being read in as
1,2,3,Hello4,
6,Wonder, ,
Here's the logic that I've been using. I really don't know what changed, so any advice would be excellent.
tableFile = fopen(argv[4], "r");
//pulling the table data from the file
char tableArray[30][50][256];
char c;
int i=0, j=0, k=0;
while(c != EOF){
c = fgetc(tableFile);
switch(c)
{
case ',':
tableArray[i][j++][k]='\0';
k=0;
break;
case '\n':
tableArray[i++][j][k]='\0';
j=0;
k=0;
break;
case '\r':
break;
case EOF:
break;
default:
tableArray[i][j][k++] = c;
break;
}
} //end file transfer
//Just to display, ignore magic numbers as (mostly) irrelevant
int a, b;
for (a = 0; a < 20; a++)
{
for (b = 0; b < 47; b++)
{
printf ("%s", tableArray[a][b]);
if (b<46)
printf (", ");
}
printf ("\n");
}
fclose(tableFile);
cinwhile (c != EOF).\n.