I'm trying to make me a little game with SDL in C with different levels. I put each level line (ASCII) to a file that I named abc.lvl. My worry is that I do not know how to read the second line of the file abc.lvl to begin at 2 and not level 1.
I hope to make myself understood.Code:int chargerNiveau (int level [] [NB_BLOC_HAUTEUR]) { FILE * file = NULL; ligneFichier char [NB_BLOC_LARGEUR NB_BLOC_HAUTEUR * + 1] = {0}; int i = 0, j = 0; file = fopen ("/ media / Mac OS / prog / c / Marion Sokoban / abc.lvl", "r"); if (file == NULL) return 0; / / We read the line niveau.lvl fgets (ligneFichier, NB_BLOC_LARGEUR NB_BLOC_HAUTEUR * + 1, file); for (i = 0; i <NB_BLOC_LARGEUR; i + +) { for (j = 0, j <NB_BLOC_HAUTEUR j + +) { switch (ligneFichier [(i * NB_BLOC_LARGEUR) + j]) { case '0 ': level [j] [i] = 0; break; case '1 ': level [j] [i] = 1; break; case '2 ': level [j] [i] = 2; break; case '3 ': level [j] [i] = 3; break; case '4 ': level [j] [i] = 4; break; } } } fclose (file); return 1; }
Bookmarks