Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int dump_med(const char *fname, struct medico **headpp)
- {
- struct medico tmp;
- FILE *f = fopen(fname, "r");
- if (f == NULL)
- {
- perror(fname);
- return -1;
- }
- while (fscanf(f, "%[^\n]", tmp.nome) == 1 &&
- fscanf(f, "%s %d.%d--%d.%d\n",
- tmp.especialidade, &(tmp.entrada.h), &(tmp.entrada.m),
- &(tmp.saida.h), &(tmp.saida.m)) == 5)
- {
- if (!(*headpp = malloc(sizeof **headpp)))
- {
- perror("Failed to allocate new list node: ");
- return -1;
- }
- // save, have headpp address the next pointer of the new node
- **headpp = tmp;
- headpp = &(*headpp)->next;
- }
- *headpp = NULL; // terminated
- fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement