Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct
- {
- char f[100]; // firstname
- char l[100]; // last name
- char n[100]; //number
- }contact; //struct name
- void main ()
- {
- FILE *fp;
- fp = fopen("phonebook.txt","w");
- printf("How many contacts do you want to add: ");
- int n;
- scanf("%d",&n);
- int i;
- contact arr[n];
- for (i=0;i<n;i++)
- {
- printf("Enter firstname: \n");
- scanf("%s", arr[i].f);
- printf("Enter lastname: \n");
- scanf("%s", arr[i].l);
- printf("Enter number: \n");
- scanf("%s", arr[i].n);
- }
- for (i=0;i<n;i++)
- {
- fprintf(fp,"%s",arr[i].f);
- fprintf(fp,",%s",arr[i].l);
- fprintf(fp,",%s.",arr[i].n);
- fprintf(fp,"\n");
- }
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement