Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct contact{
- char name[50];
- char number[10];
- char bithday[15];
- struct contact *next;
- }contact;
- struct contact *head;
- FILE *fp;
- struct contact *ap;
- fp=fopen("save_contacts.txt", "w");
- if(fp==NULL){
- printf(" Errorn");
- system("pause");
- return 1;
- }
- for (ap=head;ap!=NULL;ap=ap->next){
- fprintf(fp,"%s ",ap->name);
- //fprintf(fp,", ");
- fprintf(fp,"%s ",ap->number);
- //fprintf(fp,", ");
- fprintf(fp,"%s ",ap->birthday);
- //fprintf(fp,", ");
- fprintf(fp,"; ");
- }
- fprintf(fp, "End");
- }
- void read() {
- struct contact *ap;
- int i;
- head=NULL;
- char aux[30];
- FILE *fp=fopen("save_contacts.txt","r");
- do{
- head=NULL;
- ap=(contact*)malloc(sizeof(contact));
- fscanf(fp,"%s ",&ap->name);
- fscanf(fp,"%s ",&ap->number);
- fscanf(fp,"%s ",&ap->birthday);
- fscanf(fp,"%s ",aux);
- if(strcmp(aux,";")==0){
- ap=ap->next;
- }
- }while(strcmp(aux,"End")!=0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement