हिंदी माध्यम नोट्स
C Project : Phone-book Maintenance in hindi फ़ोन बुक मेंटेनेंस का c प्रोग्रामिंग प्रोजेक्ट हिंदी में
1. file Handling
2. Structure
3. Switch Statement
4. String Functionइस प्रोग्राम मे यूजर से 6 inputs ले सकते है | इन input के आधार हम switch statement के sepcific block को perform करगे |जैसे
Contact Number को add करने के लिए “A” enter करना होगा |
Contact Number को view करने के लिए “V” enter करना होगा|
Contact Number को Delete करने के लिए “D” enter करना होगा|
Contact Number को edit करने के लिए “E” enter करना होगा |
यूजर द्वारा दिए गये input को variable “Choice ‘ मे assign करा कर switch stement मे pass करा देते है |
switch statement मे 6 case होते है :-
case ‘X’
ये case प्रोग्राम को से exit होने के लिए होता है |इससे option से यूजर PHONEBOOK /CONSOL SCREEN terminate हो जाता है |
case ‘A’
ये case tab perform होता है यूजर add करने का option enter करता है |इसमें यूजर से contact details(namephone number,addressऔर mail ) को लेते है |इससे structure data type contact number के variable ‘contact’ मे सेव करा देते है |
फिर file input function ‘fprintf’ से in data को file ‘phone book.dll’ मे add करा देते है |
case ‘V’
ये case tab perform होता जब यूजर file ‘phone book.dll’ के सभी contacts को देखना चाहता है |
इसमें while loop मे loop तब तक चलाया जाता है जब तक की ‘phone book.dll’ के सभी contact read और console screen पर print नहीं हो जाते है |
सबसे पहले fread () function से ‘phone book.dll’ के पहले contact के address को structure variable contact मे save कराया जाता है |
फिर printf() function से , struture variable के सभी members को console screen पर print कर देते है |
case ‘S’
ये case तब perform होता है जब यूजर किसी contact को search करता है |
सबसे पहले यूजर से name of sesrched contact को input करवाया जाता है, इसे find[] मे save करा देते है |
फिर ‘phone book.dll’ के first contact के address को structure variable contact मे save कराया जाता है |फिर इस structure variable मे से member name को variable name[] मे store करा देते है |
फोर string compare function strcmp () से variable ‘find’ और variable name[] को compare करा देते है |
जहा पर function की value ‘1’ होती , address के member को print करा देते है |
अगर एक से अधिक सामान नाम की entry होती है तब count ‘found’ से number of contact का पता लगा सकते है |
case ‘E ‘
इस case मे किसी data को edit किया जाता है |इसके लिए contact का नाम यूजर से लिया जाता है |
फिर इस contact के नाम को file मे search किया जाता है |फिर बाकि की value जैसे address,mail और contact number को show किया जाता है |
case “D’
इस case मे यूजर को जो contact रखना है उसका नाम enter कर देता है |
उसके बाद use द्वारा enter name के details file ‘phone book.dll से temporary file मे transfer हो जाती है |
फिर file ‘phone book.dll डिलीट हो जाती है |
और temporary file का नाम phone book.dll रख देते है |
Source Code :
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdlib.h>
struct contact Number
{
long phone;
char name[20],address[30],mail[20];
}contact;
char find[20],name[20];
FILE *fp, *ft;
int i,n,l,found;
char choice;
int main()
{
main menu:
system(“cls”);
printf(“Enter Phonebook”);
printf(“Main Menu \n”);
printf(“Enter ‘A’ for add a new contact\n”);
printf(“Enter ‘V’ for view all contact\n”);
printf(“Enter ‘S’ for search contact”);
printf(“Enter ‘E’ for edit contact”);
printf(“Enter ‘D’ for delete contact”);
printf(“Enter ‘X’ for exit”);
printf(“Enter the choice:”);
scanf(“%c”,&choice);
switch(choice)
{
case ‘X’:
printf(“\n\n\t\tAre you sure u want to exit?”);
break;
//add contact Numbers //
case ‘A’:
system(“cls”);
fp=fopen(“phone book.dll”,”a”);
for (;;)
{
printf(” Name : “);
scanf(“%[^\n]”,&contact.name);
if(stricmp(contact.name,””)==0 || stricmp(contact.name,” “)==0) // condition check for empty or null contact name //
break;
printf(“Phone Number :”);
scanf(“%ld”,&contact.phone);
printf(“Address:”);
scanf(“%[^\n]”,&contact.add);
printf(“Mail :”);
gets(contact.email);
printf(“\n”);
fwrite(&contact,sizeof(contact),1,fp);
}
fclose(fp);
break;
// View of contact Numbers //
case ‘V’:
system(“cls”);
printf(“Detail of Contact”);
for(i=97;i<=122;i=i+1)
{
fp=fopen(“phone book.dll”,”r”);
found=0;
while(fread(&contact,sizeof(contact),1,fp)==1)
{
if(contact.name[0]==i || contact.name[0]==i-32)
{
printf(“\nName\t: %s\nphoneone\t: %ld\nAddress\t: %s\nEmail\t: %s\n”,contact.name,
contact.phone,contact.add,contact.email);
found++;
}
}
if(found!=0)
{printf(“contact found in phone book is %d”,found);
getch();}
fclose(fp);
}
break;
// Code for search contact Numbers //
case ‘S’:
system(“cls”);
do
{
found=0;
printf(“Please Enter name of person for search operation “);
scanf(“%[^\n]”,&find);
l=strlen(find);
fp=fopen(“phone book.dll”,”r”);
system(“cls”);
while(fread(&contact,sizeof(contact),1,fp)==1)
{
for(i=0;i<=l;i++)
{
name[i]=contact.name[i];
name[l]=’\0′;
if(stricmp(name,find)==0)
{
printf(“\n Contact found ! \n Name\t: %s\n Phone Number \t: %ld\n Address\t: %s\n Email\t:
%s\n”,contact.name,contact.phone,contact.add,contact.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 Enter ‘T’ for try again “);
scanf(“%c”,&choice);
}while(choice==1);
break;
// Code for edit contact Numbers //
case ‘E’:
system(“cls”);
fp=fopen(“phone book.dll”,”r”);
ft=fopen(“temp.dat”,”w”);
printf(“Enter Name that you want to edit “);
scanf(“%[^\n]”,name);
while(fread(&contact,sizeof(contact),1,fp)==1)
{
if(stricmp(name,contact.name)!=0)
fwrite(&contact,sizeof(contact),1,ft);
}
scanf(“%[^\n]”,&contact.name);
printf(“Phone Number : “);
scanf(“%ld”,&contact.phone);
printf(” Address :”);
scanf(“%[^\n]”,&contact.add);
printf(” Email :”);
gets(contact.email);
printf(“\n”);
fwrite(&contact,sizeof(contact),1,ft);
fclose(fp);
fclose(ft);
remove(“phone book.dll”);
rename(“temp.dat”,”phone book.dll”);
break;
// Code for delete contact Numbers //
case ‘D’:
system(“cls”);
printf(“Enter the name to delete:”);
scanf(“%[^\n]”,&name);
fp=fopen(“phone book.dll”,”r”);
ft=fopen(“temp.dat”,”w”);
while(fread(&contact,sizeof(contact),1,fp)!=0)
if (stricmp(name,contact.name)!=0)
fwrite(&contact,sizeof(contact),1,ft);
fclose(fp);
fclose(ft);
remove(“phone book.dll”);
rename(“temp.dat”,”phone book.dll”);
break;
default:
printf(“Invalid choice”);
break;
}
printf(“Enter Next step”);
printf(“Enter ‘M’ For main menu”);
printf(“Enter ‘E’ for Exit”)
scanf(“%c”,&choice);
switch (choice)
{
case ‘M’:
goto main menu;
case ‘E’:
break;
default:
printf(“Invalid choice”);
break;
}
getch();
}
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…