Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. typedef struct contact{
  2.  
  3. char name[50];
  4. char number[10];
  5. char bithday[15];
  6. struct contact *next;
  7. }contact;
  8.  
  9. struct contact *head;
  10. FILE *fp;
  11.  
  12. struct contact *ap;
  13.  
  14. fp=fopen("save_contacts.txt", "w");
  15.  
  16. if(fp==NULL){
  17. printf(" Errorn");
  18. system("pause");
  19. return 1;
  20. }
  21. for (ap=head;ap!=NULL;ap=ap->next){
  22. fprintf(fp,"%s ",ap->name);
  23. //fprintf(fp,", ");
  24. fprintf(fp,"%s ",ap->number);
  25. //fprintf(fp,", ");
  26. fprintf(fp,"%s ",ap->birthday);
  27. //fprintf(fp,", ");
  28. fprintf(fp,"; ");
  29. }
  30. fprintf(fp, "End");
  31. }
  32.  
  33. void read() {
  34. struct contact *ap;
  35. int i;
  36. head=NULL;
  37. char aux[30];
  38.  
  39. FILE *fp=fopen("save_contacts.txt","r");
  40.  
  41. do{
  42.  
  43. head=NULL;
  44. ap=(contact*)malloc(sizeof(contact));
  45.  
  46. fscanf(fp,"%s ",&ap->name);
  47. fscanf(fp,"%s ",&ap->number);
  48. fscanf(fp,"%s ",&ap->birthday);
  49. fscanf(fp,"%s ",aux);
  50.  
  51. if(strcmp(aux,";")==0){
  52. ap=ap->next;
  53. }
  54. }while(strcmp(aux,"End")!=0);
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement