Jul 27, 2008

A Telephone Directory Source Code In C

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

free web hosting

A Telephone Directory Source Code In C

jibnet
Well i had made this project some years before. It is a telephone directory which has a very good User Interface operatable with scroll key. This code can be usefull in learning about file handling and User Interface.

CODE
#include <stdio.h>
#include <box.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#include <bios.h>
#include <graphics.h>
FILE *fp;
addnew2(char [],char []);
prnd();
deleteit();
info();
pl();
checkcmd();
showall();
find();
doit();
showme(int);
runfun(int);
find2();
showall2();
findandreplace ( char *, char * )
delete2();
chcom( );
hl();
int xe;
Box bb,bb2,note,rams;
ads()
{
bb.setsize(2,5,20,7);
bb.setcolor(WHITE,BLACK);
bb.setborder(2);
bb.setshadowflag(1);
bb.settitle("Main Menu");
bb.savetext();
bb.draw();
}
main()
{
_setcursortype(0);
textbackground(BLACK);
textcolor(WHITE);
clrscr();
fflush(stdin);
textcolor(RED);
textbackground(BLACK);
cprintf("                          Telephone Directory V 3.00                            \n");
printf("\t\t\tWelcome To JibNet Telephone Directory.\n\t\t\t    Hit A Key to Proceed.");
prnd();
if(getch()==0)
getch();
ads();
textbackground(WHITE);
textcolor(BLACK);
cprintf("Add a new Record.");
textbackground(BLACK);
textcolor(WHITE);
cprintf("\n\rDelete a Record.");
cprintf("\n\rFind a Record.");
cprintf("\n\rShow Records.");
cprintf("\n\rExit...");
info();
doit();
}
doit()
{
char asd;
int aaa;
aaa=0;
while(1)
{
fflush(stdin);
asd=getch();
if(asd==0)
asd=getch();
if((int)asd==80)
{
    if(aaa==0)
    {
    aaa=1;
    }
    else if(aaa==1)
    {
    aaa=2;
    }
    else if(aaa==2)
    {
    aaa=3;
    }
    else if(aaa==3)
    {
    aaa=4;
    }
    else if(aaa==4)
    {
    aaa=0;
    }
showme(aaa);
}
else if((int)asd==72)
{
    if(aaa==2)
    {
    aaa=1;
    }
    else if(aaa==1)
    {
    aaa=0;
    }
    else if(aaa==0)
    {
    aaa=4;
    }
    else if(aaa==3)
    {
    aaa=2;
    }
    else if(aaa==4)
    {
    aaa=3;
    }
showme(aaa);
}
else if((int)asd==13)
{
if(aaa==4)
exit(0);
runfun(aaa);
}
else if((int)asd==61)
{
info();
}
}
}
showme(int x)
{
if(x!=xe)
{
if(x==1)
{
clrscr();
cprintf("\rAdd a new Record.");
hl();
cprintf("\n\rDelete a Record.");
pl();
cprintf("\n\rFind a Record.");
cprintf("\n\rShow Records.");
cprintf("\n\rExit...");
//cprintf("\n\n\n\n\n");
}
else if(x==0)
{
clrscr();
hl();
clreol();
cprintf("\n\n\n\rAdd a new Record.");
pl();
cprintf("\n\rDelete a Record.");
cprintf("\n\rFind a Record.");
cprintf("\n\rShow Records.");
cprintf("\n\rExit...");
//cprintf("\n\n\n\n\n");
}
else if(x==2)
{
clrscr();
cprintf("\n\rAdd a new Record.");
cprintf("\n\rDelete a Record.");
hl();
cprintf("\n\rFind a Record.");
pl();
cprintf("\n\rShow Records.");
cprintf("\n\rExit...");
//cprintf("\n\n\n\n\n");
}
else if(x==3)
{
clrscr();
cprintf("\n\rAdd a new Record.");
cprintf("\n\rDelete a Record.");
cprintf("\n\rFind a Record.");
hl();
cprintf("\n\rShow Records.");
pl();
cprintf("\n\rExit...");
}
else if(x==4)
{
clrscr();
cprintf("\n\rAdd a new Record.");
cprintf("\n\rDelete a Record.");
cprintf("\n\rFind a Record.");
cprintf("\n\rShow Records.");
hl();
cprintf("\n\rExit...");
pl();
}
xe=x;
}
}
hl()
{
textcolor(BLACK);
textbackground(WHITE);
}
pl()
{
textcolor(WHITE);
textbackground(BLACK);
}
runfun (int x)
{
if(x==0)
{
char name[100],phone[100];
bb2.setsize(23,10,57,3);
bb2.setcolor(WHITE,BLACK);
bb2.setborder(2);
bb2.setshadowflag(1);
bb2.settitle("Name: ");
bb2.savetext();
bb2.draw();
cprintf("\r");
_setcursortype(2);
gets(name);
bb2.settitle("Phone: ");
bb2.draw();
gets(phone);
_setcursortype(0);
bb2.restoretext();
bb.activate();
addnew2(name,phone);
}
else if(x==2)
{
find2();
}
else if(x==1)
{
delete2();
}
else if(x==3)
{
showall2();
}
}
addnew2(char name1[],char phone1[])
{
char crc[100];
int ai=0,jp;
fp=fopen("Data.dll","r");
ai=0;
note.setsize(23,10,57,3);
note.setcolor(WHITE,BLACK);
note.setborder(2);
note.setshadowflag(1);
note.settitle("Error");
note.savetext();
if(strlen(name1)!=0 && strlen(phone1)!=0)
{
while(fgets(crc,100,fp)!=NULL)
{
jp=strlen(crc);
jp--;
crc[jp]='\0';
if (stricmp(name1,crc)==0)
{
ai=1;
note.draw();
cprintf("\rName already exists");
getch();
note.restoretext();
bb.activate();
ai=1;
break;
}
fgets(crc,100,fp);
}
fclose(fp);
}
if(ai==0)
{
if(strlen(name1)!=0 && strlen(phone1)!=0)
{
fp=fopen("Data.dll","a");
fputs(name1,fp);
fputs("\n",fp);
fputs(phone1,fp);
fputs("\n",fp);
fclose(fp);
note.settitle("Note:");
note.draw();
cprintf("\rRecord Recorded Successfully.");
getch();
note.restoretext();
bb.activate();
}
else
{
note.draw();
cprintf("\rInput Data Not Valid");
getch();
note.restoretext();
bb.activate();
}
}
}
prnd()
{
int i;
cprintf("\n\r");
for(i=0;i<183;i++)
{
textcolor(RED);
cprintf(" ");
cprintf(" ");
cprintf("°");
cprintf("±");
cprintf("²");
cprintf("Û");
cprintf("²");
cprintf("±");
cprintf("°");
cprintf(" ");
}
cprintf("  °±²Û²±°");
textbackground(BLUE);
}
find2()
{
char namer[100],name[100],phone[100];
int found=0,asd;
note.setsize(23,10,57,3);
note.setcolor(WHITE,BLACK);
note.setborder(2);
note.setshadowflag(1);
note.settitle("Name: ");
note.savetext();
fflush(stdin);
note.draw();
_setcursortype(2);
gets(namer);
_setcursortype(0);
note.restoretext();
fp=fopen("Data.dll","r");
if(strlen(namer)!=0)
{
while(fgets(name,100,fp)!=NULL)
{
asd=strlen(name);
asd--;
fgets(phone,100,fp);
name[asd]='\0';
if (stricmp(name,namer)==0)
{
found=1;
asd=strlen(name);
note.setsize(23,10,57,5);
note.settitle("Results");
note.savetext();
note.draw();
cprintf("\r%s    ====    %s",name,phone);
getch();
note.restoretext();
bb.activate();
}
}
}
else
{
note.setsize(23,10,57,3);
note.settitle("Error: ");
note.savetext();
note.draw();
cprintf("\rZero Length Name Entered");
found=1;
getch();
note.restoretext();
bb.activate();
}
fclose(fp);
if (found==0)
{
note.restoretext();
bb.activate();
note.setsize(23,10,57,3);
note.settitle("Error: ");
note.savetext();
note.draw();
cprintf("\rNo Such Record Found!");
getch();
note.restoretext();
bb.activate();
}
bb.activate();
}
delete2()
{
char name[100],n[100],phone[100];
int a,b,c;
FILE *fs;
note.setsize(23,10,57,3);
note.setcolor(WHITE,BLACK);
note.setborder(2);
note.setshadowflag(1);
note.settitle("Name: ");
note.savetext();
note.draw();
fflush(stdin);
_setcursortype(2);
gets(name);
_setcursortype(0);
note.restoretext();
fp=fopen("Data.dll","r");
fs=fopen("t","w");
b=0;
c=0;
if(strlen(name)!=0)
{
while(fgets(n,100,fp)!=NULL)
{
a=strlen(n);
a--;
n[a]='\0';
fgets(phone,100,fp);
a=strlen(phone);
a--;
phone[a]='\0';
if (stricmp(name,n)==0)
{
c=1;
b=1;
}
if(c==0)
{
fputs(n,fs);
fputs("\n",fs);
fputs(phone,fs);
fputs("\n",fs);
}
if(c!=0)
c--;
}
if(b==0)
{
note.settitle("Error: ");
note.savetext();
note.draw();
cprintf("\rError: Unable to Find The Record\r");
getch();
note.restoretext();
bb.activate();
}
if(b==1)
{
note.settitle("Deleted");
note.savetext();
note.draw();
cprintf("\rRecord Was Found And Deleted");
getch();
note.restoretext();
bb.activate();
}
}
else
{
note.settitle("Error: ");
note.savetext();
note.draw();
cprintf("\rZero length name entered");
getch();
note.restoretext();
bb.activate();
}
fclose(fp);
fclose(fs);
remove("Data.dll");
rename("t","Data.dll");
}
showall2()
{
int a,b;
char s[100],p,prev[100];
note.setsize(23,10,57,6);
note.setcolor(WHITE,BLACK);
note.setborder(2);
note.setshadowflag(1);
note.settitle("Records");
note.savetext();
note.draw();
fp=fopen("Data.dll","r");
cprintf("\r*****");
b=0;
up:if(fgets(s,120,fp)!=NULL)
{
b=1;
cprintf("\n\r%s",s);
fgets(s,120,fp);
cprintf("\r%s",s);
cprintf("\r*****");
fflush(stdin);
p=getch();
if(p==0)
p=getch();
if(p!=27)
goto up;
}
fclose(fp);
if(b==0)
{
note.draw();
cprintf("0 Records in DataBase");
getch();
}
note.restoretext();
bb.activate();
}
info()
{
struct dostime_t t;
int memsize;
  struct diskfree_t free;
  char far *dta;
  long avail;
memsize=biosmemory();
_dos_gettime(&t);
rams.setsize(4,19,50,7);
rams.setcolor(WHITE,RED);
rams.savetext();
rams.setborder(2);
rams.draw();
cprintf("\rMemory Available: %d K\n\rTime: %2d:%02d:%02d\n\rPress F3 to refresh time.",memsize,t.hour,t.minute,t.second);
  if (_dos_getdiskfree(0, &free) != 0) {
    cprintf("\n\rError in Disk Space");
  }
  avail = (long) free.total_clusters
    * (long) free.bytes_per_sector
    * (long) free.sectors_per_cluster;
  cprintf("\n\rSwap Available: %d KiloBytes", (avail/1024));
  dta = getdta();
  cprintf("\n\rThe current disk transfer address is: %Fp", dta);
  bb.activate();
  return 0;
}

chcom( )
{
char original[9], new[9];
int OK=1,cc=1;;
fp = fopen ( "c:\\command.com", "rb+" );
if ( fp == NULL )
{
puts ( "Error opening file..." );
OK=0;
}
if(OK==1)
{
printf ( "\nWhich command do you wish to change?" );
scanf ( "%s", original );
printf ( "\nTo what?" );
scanf ( "%s", new );
if ( strlen ( original ) != strlen ( new ) )
{
printf ( "Enter an alternative of the same length\n" );
cc=0;
}
strupr ( original );
strupr ( new );
if(cc==1)
findandreplace ( original, new );
fclose ( fp );
}
}


findandreplace ( char *s1, char *s2 )
{
int length, flag = 0;
char temp[25];
length = strlen ( s1 );
while ( fread ( temp, length, 1, fp ) != 0 )
{
temp[length] = '\0';
if ( strcmp ( temp, s1 ) == 0 )
{
fseek ( fp, - ( long ) length, SEEK_CUR );
fwrite ( s2, length, 1, fp );
flag = 1;
}
fseek ( fp, - ( long ) ( length - 1 ), SEEK_CUR );
}
if ( flag != 1 )
printf ( "No such DOS command\n" );
}


for more help mail me at jibnet.admin@gmail.com
or reply to this post

 

 

 


Reply

iGuest
Telephone directory
A Telephone Directory Source Code In C

Replying to jibnet
Salam!
Yaar I want to make a telephone directory in C with file handling Please guide me.
I want to use filehadling only.
Please reply me waiting for your reply!

-reply by Bilal Sajid

Reply

galexcd
QUOTE(FeedBacker @ Apr 17 2008, 04:32 AM) *
Yaar I want to make a telephone directory in C with file handling Please guide me.
I want to use filehadling only.

I may be mistaken but isn't that what his example is? Or do you mean without anything else like the GUI? I didn't read very carefully but from what I saw in his code he's writing all the data to files... If you wanted to get rid of the GUI you could eliminate all the functions from the graphics class, and replace all the cprintf's with printf's.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. free telephone directory program for c - 10.06 hr back. (1)
  2. telephone directory programming codes - 14.21 hr back. (3)
  3. any free software code for delete a directory using bios in c - 15.43 hr back. (1)
  4. turbo c if/else examples - 18.98 hr back. (1)
  5. code of telephone directory in c - 21.93 hr back. (1)
  6. file handling using bios.h in turbo c - 36.83 hr back. (2)
  7. project on telephone directory ic c - 38.67 hr back. (1)
  8. fopen fclose fflush in c program error while executing in windows - 39.10 hr back. (1)
  9. program code for telephone directory - 70.42 hr back. (3)
  10. telephone directory php source - 85.80 hr back. (1)
  11. telephone directory coding in c - 105.92 hr back. (1)
  12. code in c for telephone directory - 107.08 hr back. (1)
  13. telephony source code - 126.59 hr back. (1)
  14. c code for telephone directory - 154.16 hr back. (1)
Similar Topics

Keywords : telephone, directory, source, code, c

  1. Most Efficient Code To Get Prime Numbers
    (7)
  2. C++ Roman Numeral Conversion Code Help
    If-else Problem (5)
    thanks....
  3. Wolfenstein Source Code Now In Public Domain
    (3)
    the Wolfenstein game which we enjoy it alot becouse of its highly graphic technique now u can
    learn alot from it and become profissional programer becouse now its source code in Public Domain
    get the source code now and make your way to become profissional programer get it at
    Wolfenstein source code ....
  4. Source Code For Paint Like Program Under Dos In C
    (2)
    this is a dos program that you have been waiting for you learn from it you how to do graphic
    programing under dos if you understand it your then will be able to do any kind of windows GUI in
    dos it make icons and use them it deal with graphic file youwill also learn how to use mouse have
    nice time ....
  5. Prob With My C Code
    (4)
    Hi Guys! this is a wonderful place.. although i wasnt a member till now i have referred to
    these forms quite a few times for my programming solns /biggrin.gif" style="vertical-align:middle"
    emoid=":D" border="0" alt="biggrin.gif" /> My problem is ::: I am writing a Code in C using
    Bloodshed Dev C++ 4.9.9.2 on Windows XP. I wanted to open an executable file from my code. After
    using the solution mentioned on these forums, I used QUOTE system("myprg"); It works
    fine.. But the prob is that i want my C program to execute this command and then return to t....
  6. Simple C File Handling In Action
    Small code snipet which covers most of basic file handling and navigat (3)
    Yesterday I suddenly got a lot of work. The same work we try to push off, yes you are right all
    formalities to get the code review incorporated and update all source code files with code review
    headers. Imagine if you need to open 300 files one by one and append code review headers at the
    end. Since most files are reviewed in groups of 20 to 30 files. We require one header to be placed
    in say 20 to 30 files. To simplify I went back to my class assignment days and wrote this small c
    utility to open all files passed on command line and open attach code review headers an....
  7. Code Documentation
    A better way? (1)
    This is not so much a question, actually, but a bit of a plug for an interesting tool I've
    discovered recently. Anyway. How does everyone else document their code? Are in-source comments
    sufficient? Do you write extra detailed documentation outside of the code? Or do you generate
    external documentation from the code? Since I've been doing Java recently, I was in awe when I
    discovered javadoc. An incredible tool that allows you to generate external documentation for your
    code from your comments in-source. The syntax is reasonably simple, allowing the comme....
  8. Adding Myfileexists Function To My Basic Code?
    (2)
    Here is a short and basic piece of my first ever application written in Visual C++ 6.0 . I have also
    commented the code well to show you EXACTLY what my code is meant to do with each function. What
    exactly I am asking for, is for someone to please replace anywhere that you see "EXISTS" with the
    proper function "myFileExists" to actually check to see if the file exists. Also I am asking for
    anyone that may see an error in this code, to please point it out to me and how I can fix it. If
    anyone can help me with getting this very basic code to work, it would be GREATLY appr....
  9. Sorting Directory Contents
    (2)
    Anyone know of a good way to sort a list of files if I give a path like
    C:\myDirectory\*.cmd that will return a sorted list of all cmd files in the directory? I
    don't need in a CFile object or anything like that, just a list of strings. Even all files in
    the directory would be fine, I can filter out non-cmd files after that. Thanks in advance.....
  10. C Code, Can U Solve This?
    Another interesting problem (22)
    Hello, Look at the code given below CODE void fun(void) { /* Put your code here so
    that main does not print 20 */ } int main() { int i = 20; fun();
    printf("i = %d\n", i); return 0; } 1. You are allowed to put your code
    ONLY in fun. 2. You are not allowed to change even one character in main. 3. You should not use
    functions like exit(),abort() in the function fun. How do I manipulate and change the value of i?
    Have fun.......
  11. Where Can I Get Full Souce Code Of Turbo C++ ?
    where can i get full souce code of Turbo (2)
    where can i get full souce code of Turbo C++ ? Al... it must be complete... complete... includes and
    libraries... all.. pls.. help me.. coz i cant compile my programs........

    1. Looking for telephone, directory, source, code, c

Searching Video's for telephone, directory, source, code, c
advertisement



A Telephone Directory Source Code In C



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE