print in file bug patched
This commit is contained in:
1 parent
06a0ef2466
commit
633a3ff56b
4 files changed
+21
-3
No files matched your search
@@ -19,4 +19,13 @@ void test_output(int i, int excepted, char* message) {
|
||||
fprintf(stderr, message);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int get_nb_char_from_int(unsigned int number) {
|
||||
unsigned int res = 0;
|
||||
do {
|
||||
res++;
|
||||
number = number / 10;
|
||||
} while (number != 0);
|
||||
return res;
|
||||
}
|
||||
@@ -37,4 +37,12 @@ void checkPointer(void* p, char* errMessage);
|
||||
*/
|
||||
void test_output(int i, int excepted, char* message);
|
||||
|
||||
/**
|
||||
* @brief Get the nb char from int object
|
||||
*
|
||||
* @param number
|
||||
* @return unsigned int
|
||||
*/
|
||||
unsigned int get_nb_char_from_int(unsigned int number);
|
||||
|
||||
#endif
|
||||
+2
-2
@@ -60,8 +60,8 @@ int main(int argc, char* argv[]) {
|
||||
char* filename = argv[3];
|
||||
FILE* f = fopen(filename, "w");
|
||||
checkPointer((void*)f, "\nCouldn't open file in game_solve executable\n");
|
||||
uint nbchar_nbsolution = nbSolutions / 10;
|
||||
test_output(fprintf(f, "%u\n", nbSolutions), nbchar_nbsolution + 1, "\nError when printing in file in game_solve executable\n");
|
||||
test_output(fprintf(f, "%u\n", nbSolutions), get_nb_char_from_int(nbSolutions) + 1 /*for the \n*/,
|
||||
"\nError when printing in file in game_solve executable\n");
|
||||
fclose(f);
|
||||
printf(", this number has been saved in file named : %s", filename);
|
||||
}
|
||||
|
||||
+2
-1
@@ -82,7 +82,8 @@ void game_save(cgame g, char* filename) {
|
||||
checkPointer((void*)f, "Couldn't open file in game_save\n");
|
||||
// try to print the first line (game_nb_rows(g) / 10 + 1 = nb char of a number)
|
||||
test_output(fprintf(f, "%d %d %d\n", game_nb_rows(g), game_nb_cols(g), game_is_wrapping(g)),
|
||||
NB_CHAR_HEADER_WITHTOUT_DIMENSIONS + game_nb_rows(g) / 10 + 1 + game_nb_cols(g) / 10 + 1, "Couldn't print in file.\n");
|
||||
NB_CHAR_HEADER_WITHTOUT_DIMENSIONS + get_nb_char_from_int(game_nb_rows(g)) + get_nb_char_from_int(game_nb_cols(g)),
|
||||
"Couldn't print in file.\n");
|
||||
// for each case of the game get the char of the given case and try to print it on the file
|
||||
for (uint i = 0; i < game_nb_rows(g); i++) {
|
||||
for (uint j = 0; j < game_nb_cols(g); j++) {
|
||||
|
||||
Reference in new issue
Block a user