




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A C program for creating and managing a contact list using a file. The user can add, list, search, edit, and delete contacts from the list. The program uses various libraries such as stdio, conio, string, process, and dos. The user interacts with the main menu to perform various operations on the contact list.
Typology: Cheat Sheet
1 / 8
This page cannot be seen from the preview
Don't miss anything!





#include<stdio.h> #include<conio.h> #include<string.h> #include<process.h> #include<stdlib.h> #include<dos.h> struct contact { long ph; char name[20],add[20],email[30]; } list; char query[20],name[20]; FILE *fp, ft; int i,n,ch,l,found; //Start of main// int main() { system("cls"); / ************Main menu *********************** */ system("color 3f"); printf("\n\t **** Knowledge 360 ****"); printf("\n\t **** Welcome to Contact Management System ****"); printf("\n\n\n\t\t\tMAIN MENU\n\t\t=====================\n\t\t[1] Add a New Contact\n\t\t[2] List all Contacts\n\t\t[3] Search for Contact\n\t\t[4] Edit a Contact\n\t\t[5] Delete a Contact\n\t\t[0] Exit\n\t\t=================\n\t\t"); printf("Enter Your Choice: "); scanf("%d",&ch); switch(ch) { case 0: printf("\n\n\t\tAre You Sure To Exit?");
break; case 1: system("cls"); fp=fopen("contact.dll","a"); for (;;) { fflush(stdin); printf("To Exit Enter Blank Space in the Name Input\nName (Use identical): "); scanf("%[^\n]",&list.name); if(stricmp(list.name,"")==0 || stricmp(list.name," ")==0) break; fflush(stdin); printf("Phone: "); scanf("%ld",&list.ph); fflush(stdin); printf("Address: "); scanf("%[^\n]",&list.add); fflush(stdin); printf("Email Address: "); gets(list.email); printf("\n"); fwrite(&list,sizeof(list),1,fp); } fclose(fp); break; case 2: system("cls"); printf("\n\t\t================================\n\t\t\tLIST OF CONTACTS\n\t\t================================\n\nName\t\tPhone No\t Address\t\tE- mail\n=================================================================\n\n"); for(i=97; i<=122; i=i+1) { fp=fopen("contact.dll","r"); fflush(stdin);
for(i=0; i<=l; i++) name[i]=list.name[i]; name[l]='\0'; if(stricmp(name,query)==0) { printf("\n..::Name\t: %s\n..::Phone\t: %ld\n..::Address\t: %s\n..::Email\t: %s\n",list.name,list.ph,list.add,list.email); found++; if (found%4==0) { printf("..::Press any key to continue..."); getch(); } } } if(found==0) printf("\n..::No match found!"); else printf("\n..::%d match(s) found!",found); fclose(fp); printf("\n ..::Try again?\n\n\t[1] Yes\t\t[0] No\n\t"); scanf("%d",&ch); } while(ch==1); break; case 4: system("cls"); fp=fopen("contact.dll","r"); ft=fopen("temp.dat","w"); fflush(stdin); printf("..::Edit contact\n===============================\n\n\t..::Enter the name of contact to edit:"); scanf("%[^\n]",name);
while(fread(&list,sizeof(list),1,fp)==1) { if(stricmp(name,list.name)!=0) fwrite(&list,sizeof(list),1,ft); } fflush(stdin); printf("\n\n..::Editing '%s'\n\n",name); printf("..::Name(Use identical):"); scanf("%[^\n]",&list.name); fflush(stdin); printf("..::Phone:"); scanf("%ld",&list.ph); fflush(stdin); printf("..::address:"); scanf("%[^\n]",&list.add); fflush(stdin); printf("..::email address:"); gets(list.email); printf("\n"); fwrite(&list,sizeof(list),1,ft); fclose(fp); fclose(ft); remove("contact.dll"); rename("temp.dat","contact.dll"); break; case 5: system("cls"); fflush(stdin); printf("\n\n\t..::DELETE A CONTACT\n\t==========================\n\t..::Enter the name of contact to delete:"); scanf("%[^\n]",&name); fp=fopen("contact.dll","r"); ft=fopen("temp.dat","w");