#define MAX_READING 100;
char str_orders[MAX_READING], str_books[MAX_READING],
books_updated[MAX_READING], *token, *token1, p[MAX_READING],
File * books_orders, *books, books_updated;
while (fgets (str_orders, MAX_READING, books_orders) != NULL) {
if (str_orders[strlen (str_orders) - 1] == '\n')
str_orders[(strlen (str_orders) - 1)] = 0;
if (strcmp (str_orders, "Initialize") == 0) {
while (fgets (str_books, MAX_READING, books) != NULL) {
if (str_books[strlen (str_books) - 1] == '\n')
str_books[(strlen (str_books) - 1)] = 0;
token = strtok (str_books, "$$$");
strcpy (p, token);
token = strtok (NULL, "$$$");
copy = atoi (token);
add (head, p, copy);
}
}
printf ("%s\n", str_orders);
if (strcmp (str_orders, "Initialize") != 0
&& strcmp (str_orders, "Finalize") != 0) {
token1 = strtok (str_orders, "$$$");
strcpy (order, token1);
token1 = strtok (NULL, "$$$");
strcpy (book_name, token1);
token1 = strtok (NULL, "$$$");
copy = atoi (token1);
if (strcmp (order, "Return") == 0)
returnbook (head, book_name, copy);
if (strcmp (order, "Borrow") == 0)
borrowbook (head, book_name, copy);
if (strcmp (str_orders, "Finalize") == 0) {
while (head != NULL) {
fprintf (books_update, "%s", head->name);
fprintf (books_update, " $$$ ");
fprintf (books_update, "%d", head->copies);
}
}
}
I'm trying to read line by line from a txt file in C.
I used the fgets
function to read them, but the function reads the first line called "Intalize", doesn't proceed to other lines in the file. I tried to
printf("%s",str_orders)
and it's returning "Intalize". The fgets
didn't proceed to the lines.
How can I fix that?