Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct Node
- {
- char Name[80], Phone[80], Email[80];
- struct Node *next;
- } Node;
- typedef struct Queue
- {
- struct Node *head;
- } Queue;
- Node *front(Queue q);
- {
- if (q.head == NULL)
- return;
- return q.head;
- }
- Queue *makeQueue()
- {
- Queue *q;
- q = (Queue *)malloc(sizeof(Queue));
- q->head = NULL;
- return q;
- }
- void pop(Queue *q)
- {
- Node *tmp;
- if (q.head == NULL)
- {
- printf("ERROR\n");
- return;
- }
- Node *tmp = q.head;
- q.head = q.head->next;
- free(tmp);
- }
- void push(Queue *q, Node *node)
- {
- Node *iterator;
- if (q.head == NULL)
- {
- q.head = iterator;
- return;
- }
- Node *iterator = q.head;
- while (iterator->next != NULL)
- {
- iterator = iterator->next;
- }
- iterator->next = p;
- return;
- }
- int main()
- {
- Queue *q = makeQueue();
- FILE *f;
- f = fopen("phonebook.txt", "r");
- if (f == NULL)
- {
- printf("ERROR");
- }
- else
- {
- char s1[80], s2[80], s3[80];
- do
- {
- fscanf(f, "%s %s %s", s1, s2, s3);
- while (feof(f))
- {
- Node *newNode = makeNode(s1, s2, s3);
- push(q, newNode);
- }
- }
- }
- Node *node = q.front();
- q.pop();
- while (node != NULL)
- {
- node = q.front();
- q.pop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment