My question is why atoi returns a value of -954337623 or something like that in the following function.
The fgets function reads from a textfile which holds 20 rows of 1s, 0s and newline chars.
Code:int getmap(int map[20][50]) { int x = 0, y = 0; char rdBuffer[50], c; FILE* mapfile = fopen(MAP_NAME, "r"); if (mapfile == NULL) { printf("Could not open file properly"); return MAPERROR; } for (;y < 20; y++) { fgets(rdBuffer, 50, mapfile); for (; x < 50; x++) { c = rdBuffer[x]; map[y][x] = atoi(&c); // Need help here, please! if (map[y][x] != 1 && map[y][x] != 0) { return MAPERROR; } else { switch(map[y][x]) { case 1: printf("#"); break; case 0: printf(" "); break; default: ; } } } printf("\n"); x = 0; } fclose(mapfile); return 0; }



LinkBack URL
About LinkBacks


