Okay... I'm trying to read a map file in integer by integer ignoring commas and newlines and this is the code I've written so far:

Code:
void LoadWorld (const char* fn)
{
	FILE *f;
	if ((f = fopen(fn, "r")) == NULL)
		return; 

	for (int y = 0; y < MAP_H; ++y) {
		for (int x = 0; x < MAP_W; ) {
			int c = getw(f);

			if (feof(f))
				break;
			
			if (char(c) != '\n' &&
				char(c) != ',') {
				MAP[y][x] = c;
				++x;
			}
		}
	}

	fclose(f);
}
Now for some strange (or completely normal, understandable) reason, this works but has some garbled blocks left over. My map file is a text file formatted like this:

1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,2,

etc...

MAP_W and MAP_H are the right numbers. What am I overlooking in this that makes it not read it all (it just reads the second half it seems, the rest of the map is left as 0s)? Also what would be a good way to do this without using getw(), as I understand it's not good for portable code. (I tried using fscanf(f,"%d,",&c) but that doesn't work at all)

Thank you for any help