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;
- struct Node *prev;
- } Node;
- Node *head;
- Node *tail;
- Node* makeNode(char *s1, char* s2, char* s3)
- {
- Node*p = (Node*)malloc(sizeof(Node));
- strcpy(p->Name,s1);
- strcpy(p->Phone,s2);
- strcpy(p->Email,s3);
- p->next = NULL;
- p->prev = NULL;
- return p;
- }
- void addNode(Node* p)
- {
- if(head == NULL)
- {
- head = p;
- tail = p;
- return;
- }
- tail->next = p;
- p->prev = tail;
- p = tail;
- }
- void printfll(Node* p)
- {
- while(p != NULL)
- {
- printf("%s %s %s\n", p->Name, p->Phone, p->Email);
- printfll(p->next);
- }
- }
- int main(){
- 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);
- Node* newNode = makeNode(s1,s2,s3);
- addNode(newNode);
- }while(!feof(f));
- }
- printfll(head);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment