Removed getline (gosha gtfo!)

feature-fix-condition
germanFid 2022-10-24 10:42:00 +03:00
parent ceb9fa9c05
commit 63c107f7cb
2 changed files with 5 additions and 7 deletions

View File

@ -22,6 +22,7 @@
#define FALSE 0 #define FALSE 0
// file // file
#define MAX_STRING_SIZE 1000
#define FILE_OPENING_ERROR "Cannot open the %s file.\n" #define FILE_OPENING_ERROR "Cannot open the %s file.\n"
/// <summary> /// <summary>

View File

@ -3,11 +3,11 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
FILE *IFile = NULL; FILE *IFile = NULL;
char *ILine = NULL; char ILine[MAX_STRING_SIZE + 1];
int16_t len = 0; int16_t len = 0;
int32_t read; int32_t read;
char WRead[300]; char WRead[MAX_STRING_SIZE];
if (argc > 1) if (argc > 1)
{ {
@ -27,18 +27,15 @@ int main(int argc, char **argv)
printf("Wrong Arguments!\nUsage ./Lab.exe -f <file.txt>\n"); printf("Wrong Arguments!\nUsage ./Lab.exe -f <file.txt>\n");
exit(WRONG_ARGUMENT_FAILURE); exit(WRONG_ARGUMENT_FAILURE);
} }
while ((read = getline(&ILine, &len, IFile)) != -1) while ((read = fgets(&ILine, MAX_STRING_SIZE, IFile)) != NULL)
{ {
// printf("Retrieved line of length %zu:\n", read);
printf("%s", ILine); printf("%s", ILine);
parceLine(ILine); parceLine(ILine);
} }
printDataBase(); printDataBase();
fclose(IFile); fclose(IFile);
if (ILine)
free(ILine);
exit(EXIT_SUCCESS); // Comment if you want continious reading after parsing file exit(EXIT_SUCCESS); // Comment if you want continious reading after parsing file
} // if (argc > 1) -- correct } // if (argc > 1) -- correct