diff options
author | rafa_99 <rafa99@protonmail.com> | 2020-11-22 14:23:05 +0000 |
---|---|---|
committer | rafa_99 <rafa99@protonmail.com> | 2020-11-22 14:23:05 +0000 |
commit | 7b644262f9ef0b5e5d5f5463b9cf96b78b67bfed (patch) | |
tree | c809ded185e51b46663c80d421d620738cc638cf /utils.c | |
parent | 596b63a8700e2953ce81b65f46a5b3015d45d904 (diff) |
Fixed Problem With Line Size
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -14,27 +14,25 @@ int lineCounter(FILE *dictionary) int words = 0; if ( dictionary != NULL ) { - char line[256]; - while ( !feof(dictionary) ) + char line[MAX_LINE]; + for( words; (!feof(dictionary)); words++ ) { - fgets(line, sizeof(line), dictionary); - words++; + fgets(line, MAX_LINE, dictionary); } - words--; rewind(dictionary); + words--; } - return words; } char* getLine(FILE *dictionary, int lineNumber) { - char *line = (char *) calloc(256, sizeof(char)); + char *line = (char *) calloc(MAX_LINE, sizeof(char)); if ( dictionary != NULL ) { - for ( int i = 0; (!feof(dictionary) && i != lineNumber - 1); i++) + for ( int i = 0; (!feof(dictionary) && i != lineNumber ); i++) { - fgets(line, sizeof(line), dictionary); + fgets(line, MAX_LINE, dictionary); } rewind(dictionary); } |