Add file line-by-line reading

feature-input-file
germanFid 2022-10-23 22:50:18 +03:00
parent 5ea9b6b96e
commit 035b1c8378
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,6 @@
insert last_nm=Ulanovsky, first_nm=George, curse_id=2, lab_id=2, start_tm=2000.10.10!22:1:20, end_tm=2000.10.10!23:0:20, result=[]
insert last_nm=Ulanovsky, first_nm=George, curse_id=1, lab_id=3, start_tm=2000.10.10!22:1:20, end_tm=2000.10.10!23:0:20, result=[]
insert last_nm=Ulanovsky, first_nm=George, curse_id=2, lab_id=4, start_tm=2000.10.10!22:1:20, end_tm=2000.10.10!23:0:20, result=[]
uniq first_nm

View File

@ -0,0 +1,40 @@
#include "parcer.h"
int main(int argc, char** argv)
{
FILE* IFile = NULL;
char* ILine = NULL;
size_t len = 0;
ssize_t read;
if (argc > 1)
{
if (argc == 3)
{
// argc OK!
IFile = fopen(argv[2], "r");
if (IFile == NULL)
{
printf("Wrong File!\n");
exit(WRONG_ARGUMENT_FAILURE);
}
}
else
{
printf("Wrong Arguments!\nUsage ./Lab.exe -f <file.txt>\n");
exit(WRONG_ARGUMENT_FAILURE);
}
while ((read = getline(&ILine, &len, IFile)) != -1) {
// printf("Retrieved line of length %zu:\n", read);
printf("%s", ILine);
parceLine(ILine);
}
fclose(IFile);
if (ILine)
free(ILine);
exit(EXIT_SUCCESS);
} // if (argc > 1) -- correct
}