nguyentruong98

Untitled

Nov 7th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef struct Node
  4. {
  5.       char Name[80], Phone[80], Email[80];
  6.       struct Node *next;
  7.       struct Node *prev;
  8. } Node;
  9. Node *head;
  10. Node* makenode(char *s1, char* s2, char* s3)
  11. {
  12.       Node*p = (Node*)malloc(sizeof(Node));
  13.       strcpy(p->Name,s1);
  14.       strcpy(p->Phone,s2);
  15.       strcpy(p->Email,s3);
  16.       p->next = NULL;
  17.       p->prev = NULL;
  18.       return p;
  19. }
  20. Node* addNode(char* s1, char* s2, char* s3)
  21. {
  22.       Node*p = (Node*)malloc(sizeof(Node));
  23.       tail->next = p;
  24.       p->prev = tail;
  25.       p = tail;
  26.       strcpy(p->Name,s1);
  27.       strcpy(p->Phone,s2);
  28.       strcpy(p->Email,s3);
  29.       return p;
  30. }
  31. void printll(Node* p)
  32. {
  33.       while(p != NULL)
  34.       {
  35.             printf("%s %s %s\n", p->Name, p->Phone, p->Email);
  36.             printfll(p->next);
  37.       }
  38. }
  39. int main(){
  40.       FILE *f;
  41.       f = fopen("phonebook.txt", "r");
  42.       if (f == NULL)
  43.       {
  44.             printf("ERROR");
  45.       }
  46.       else
  47.       {
  48.             char s1[80], s2[80], s3[80];
  49.             do{
  50.                   fscanf(f, "%s %s %s", s1, s2, s3);
  51.                   Node* newNode = makeNode(s1,s2,s3);
  52.             }while(!feof(f));
  53.       }
  54.       printll(head);
  55.       return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment