Help with a project:

This is a discussion on Help with a project: within the C Programming forums, part of the General Programming Boards category; PHONEBOOK: enter name: enter address: TEL. No.: Mobile Number: ^ Finished The project must 1.) ADD ENTRY 2.) SORT ENTRY ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    19

    Help with a project:

    PHONEBOOK:
    enter name:
    enter address:
    TEL. No.:
    Mobile Number:
    ^ Finished


    The project must
    1.) ADD ENTRY
    2.) SORT ENTRY - a.) Sort by first name b.) Sort by surname
    3.) DELETE ENTRY
    a.) Delete whole entry
    b.) delete one entry only
    c.) delete all

    here's what we tried so far:
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    #include "box.h"
    #include "loading.h"
    
    typedef struct{
    	char firstname[50];
    	char familyname[50];
    	char address[50];
    	char telno[15];
    }StudentInfo;
    
    input();
    display();
    find();
    
    main()
    {
    		FILE *fp;
    		char ch;
    
    		clrscr();
    
    		if(fopen("directory.txt","rb")==NULL)
    		loading();
    
    		for(;;)
    		{
    			ch=menu();
    
    			    switch(ch)
    			    {
    					case 'e': input();
    						break;
    					case 'd': display();
    						break;
    					case 'f': find();
    						break;
    					case 'q': exit(1);
    			    }
    		}
    }
    
    
    menu()
    {
    	char ch,select;
    
    
    box();
    textcolor(YELLOW);
    
    do
    {
    d1:
    
    textcolor(14);textbackground(0);
    gotoxy(36,14);cprintf("   Enter Data   ");
    textcolor(15);textbackground(1);
    gotoxy(36,15);cprintf("   Find Input   ");
    textcolor(15);textbackground(1);
    gotoxy(36,16);cprintf("   Display Data ");
    textcolor(15);textbackground(1);
    gotoxy(36,17);cprintf("   Exit         ");
    ch=getch();
    }
    while((ch!=72)&&(ch!=80)&&(ch!=13));
    if(ch==72)goto d4;
    if(ch==80)goto d2;
    if(ch==13){select=1;goto down;}
    
    
    do
    {
    d2:
    
    textcolor(15);textbackground(1);
    gotoxy(36,14);cprintf("   Enter Data   ");
    textcolor(14);textbackground(0);
    gotoxy(36,15);cprintf("   Find Input   ");
    textcolor(15);textbackground(1);
    gotoxy(36,16);cprintf("   Display Data ");
    textcolor(15);textbackground(1);
    gotoxy(36,17);cprintf("   Exit         ");
    ch=getch();
    }
    while((ch!=72)&&(ch!=80)&&(ch!=13));
    if(ch==72)goto d1;
    if(ch==80)goto d3;
    if(ch==13){select=2;goto down;}
    
    
    do
    {
    d3:
    
    textcolor(15);textbackground(1);
    gotoxy(36,14);cprintf("   Enter Data   ");
    textcolor(15);textbackground(1);
    gotoxy(36,15);cprintf("   Find Input   ");
    textcolor(14);textbackground(0);
    gotoxy(36,16);cprintf("   Display Data ");
    textcolor(15);textbackground(1);
    gotoxy(36,17);cprintf("   Exit         ");
    ch=getch();
    }
    while((ch!=72)&&(ch!=80)&&(ch!=13));
    if(ch==72)goto d2;
    if(ch==80)goto d4;
    if(ch==13){select=3;goto down;}
    
    do
    {
    d4:
    
    textcolor(15);textbackground(1);
    gotoxy(36,14);cprintf("   Enter Data   ");
    textcolor(15);textbackground(1);
    gotoxy(36,15);cprintf("   Find Input   ");
    textcolor(15);textbackground(1);
    gotoxy(36,16);cprintf("   Display Data ");
    textcolor(14);textbackground(0);
    gotoxy(36,17);cprintf("   Exit         ");
    ch=getch();
    }
    while((ch!=72)&&(ch!=80)&&(ch!=13));
    if(ch==72)goto d3;
    if(ch==80)goto d1;
    if(ch==13){select=4;goto down;}
    
    down:
    if(select==1)input();
    if(select==2)find();
    if(select==3)display();
    if(select==4)exit(1);
    }
    
    input()
    {
    	FILE *fp;
    	StudentInfo donna;
    	clrscr();
    	fp=fopen("directory.txt","ab");
    
    	printf("Enter first name: ");
    	gets(donna.firstname);
    	printf("Enter family name: ");
    	gets(donna.familyname);
    	printf("Enter address: ");
    	gets(donna.address);
    	printf("Enter no: ");
    	gets(donna.telno);
    
    	fwrite(&donna,sizeof(StudentInfo),1,fp);
    	fclose(fp);
    
    }
    
    
    find()
    {
    	FILE *fp;
    	StudentInfo donna;
    	char name[50];
    
            fp=fopen("directory.txt","rb");
    
    	printf("Enter first name to find: ");
    	gets(name);
    
    
    
    
    	while(!feof(fp))
    	{
    		fread(&donna,sizeof(StudentInfo),1,fp);
    
    		if(strcmp(name,donna.firstname)==0)
    		{
    			printf("\nFirst name: %s",donna.firstname);
    			printf("\nFamily name: %s",donna.familyname);
    			printf("\nAddress: %s",donna.address);
    			printf("\nTelephone no: %s",donna.telno);
    
    		}
    
    	else	{
    			if(feof(fp))
    				printf("\nName not found in directory");
    		}
    	}
    	getch();
    	fclose(fp);
    
    }
    
    display()
    {
    	FILE *fp;
    	StudentInfo donna;
    	clrscr();
    	fp=fopen("directory.txt","rb");
    
    	printf("FIND DATA");
    
    	printf("\n\n\tFirstname\tFamily name\tAddress\t\tTelephone no");
    
    	while(!feof(fp))
    	{
    	fread(&donna,sizeof(StudentInfo),1,fp);
    	printf("\n\n%9s %15s %15s %15s",donna.firstname,
    				donna.familyname,
    				donna.address,
    				donna.telno);
    
    
    	}
    	getch();
    
    	fclose(fp);
    }
    box.h file
    Code:
    #include<stdio.h>
    #include<graphics.h>
    
    void box()
    {
    int background();
    
    clrscr();
    textbackground(BLACK);
    gotoxy(1,1);cprintf("                                                                                ");
    gotoxy(1,2);cprintf("                                                                                ");
    gotoxy(1,3);cprintf("                                                                                ");
    gotoxy(1,4);cprintf("                                                                                ");
    gotoxy(1,5);cprintf("                                                                                ");
    gotoxy(1,6);cprintf("                                                                                ");
    gotoxy(1,7);cprintf("                                                                                ");
    gotoxy(1,8);cprintf("                                                                                ");
    gotoxy(1,9);cprintf("                                                                                ");
    gotoxy(1,10);cprintf("                                                                                ");
    gotoxy(1,11);cprintf("                                                                                ");
    gotoxy(1,12);cprintf("                                                                                ");
    gotoxy(1,13);cprintf("                                                                                ");
    gotoxy(1,14);cprintf("                                                                                ");
    gotoxy(1,15);cprintf("                                                                                ");
    gotoxy(1,16);cprintf("                                                                                ");
    gotoxy(1,17);cprintf("                                                                                ");
    gotoxy(1,18);cprintf("                                                                                ");
    gotoxy(1,19);cprintf("                                                                                ");
    gotoxy(1,20);cprintf("                                                                                ");
    gotoxy(1,21);cprintf("                                                                                ");
    gotoxy(1,22);cprintf("                                                                                ");
    gotoxy(1,23);cprintf("                                                                                ");
    gotoxy(1,24);cprintf("                                                                                ");
    gotoxy(1,25);cprintf("                                                                                ");
    
    textbackground(LIGHTBLUE);
    gotoxy(32,4);cprintf("                       ");
    gotoxy(32,5);cprintf("                       ");
    gotoxy(32,6);cprintf("                       ");
    gotoxy(32,7);cprintf("                       ");
    gotoxy(32,8);cprintf("                       ");
    gotoxy(32,9);cprintf("                       ");
    gotoxy(32,10);cprintf("                       ");
    gotoxy(32,11);cprintf("                       ");
    gotoxy(32,12);cprintf("                       ");
    gotoxy(32,13);cprintf("                       ");
    gotoxy(32,14);cprintf("                       ");
    gotoxy(32,15);cprintf("                       ");
    gotoxy(32,16);cprintf("                       ");
    gotoxy(32,17);cprintf("                       ");
    gotoxy(32,18);cprintf("                       ");
    gotoxy(32,19);cprintf("                       ");
    gotoxy(32,20);cprintf("                       ");
    
    /*outer box*/
    
    textcolor(BLACK);
    
    gotoxy(32,4);cprintf("旼컴컴컴컴컴컴컴컴컴컴");
    gotoxy(32,5);cprintf("");
    gotoxy(32,6);cprintf("");
    gotoxy(32,7);cprintf("");
    gotoxy(32,8);cprintf("");
    gotoxy(32,9);cprintf("");
    gotoxy(32,10);cprintf("");
    gotoxy(32,11);cprintf("");
    gotoxy(32,12);cprintf("");
    gotoxy(32,13);cprintf("");
    gotoxy(32,14);cprintf("");
    gotoxy(32,15);cprintf("");
    gotoxy(32,16);cprintf("");
    gotoxy(32,17);cprintf("");
    gotoxy(32,18);cprintf("");
    gotoxy(32,19);cprintf("");
    gotoxy(32,20);cprintf("");
    
    /*outer box2*/
    textcolor(LIGHTCYAN);
    
    gotoxy(55,4);cprintf("");
    gotoxy(55,5);cprintf("");
    gotoxy(55,6);cprintf("");
    gotoxy(55,7);cprintf("");
    gotoxy(55,8);cprintf("");
    gotoxy(55,9);cprintf("");
    gotoxy(55,10);cprintf("");
    gotoxy(55,11);cprintf("");
    gotoxy(55,12);cprintf("");
    gotoxy(55,13);cprintf("");
    gotoxy(55,14);cprintf("");
    gotoxy(55,15);cprintf("");
    gotoxy(55,16);cprintf("");
    gotoxy(55,17);cprintf("");
    gotoxy(55,18);cprintf("");
    gotoxy(55,19);cprintf("");
    gotoxy(33,20);cprintf("컴컴컴컴컴컴컴컴컴컴컴");
    
    
    
    
    textcolor(BLACK);
    gotoxy(36,5);cprintf("컴컴컴컴컴컴컴컴");
    gotoxy(52,6);cprintf("");
    gotoxy(52,7);cprintf("");
    gotoxy(52,8);cprintf("");
    
    /*inner box*/
    textbackground(LIGHTBLUE);
    textcolor(LIGHTCYAN);
    gotoxy(35,5);cprintf("");
    gotoxy(35,6);cprintf("");
    gotoxy(35,7);cprintf("");
    gotoxy(35,8);cprintf("읕컴컴컴컴컴컴컴");
    
    /*inner box lower */
    
    gotoxy(35,11);cprintf("");
    gotoxy(35,12);cprintf("");
    gotoxy(35,13);cprintf("");
    gotoxy(35,14);cprintf("");
    gotoxy(35,15);cprintf("");
    gotoxy(35,16);cprintf("");
    gotoxy(35,17);cprintf("");
    gotoxy(35,18);cprintf("읕컴컴컴컴컴컴컴");
    
    textcolor(BLACK);
    gotoxy(36,11);cprintf("컴컴컴컴컴컴컴컴");
    gotoxy(52,12);cprintf("");
    gotoxy(52,13);cprintf("");
    gotoxy(52,14);cprintf("");
    gotoxy(52,15);cprintf("");
    gotoxy(52,16);cprintf("");
    gotoxy(52,17);cprintf("");
    gotoxy(52,18);cprintf("");
    
    
    
    
    }
    loading.h file
    Code:
    #include<stdio.h>
    #include<graphics.h>
    
    
    void loading()
    {
    int background();
    int x,y;
    
    clrscr();
    textbackground(BLACK);
    gotoxy(1,1);cprintf("                                                                                ");
    gotoxy(1,2);cprintf("                                                                                ");
    gotoxy(1,3);cprintf("                                                                                ");
    gotoxy(1,4);cprintf("                                                                                ");
    gotoxy(1,5);cprintf("                                                                                ");
    gotoxy(1,6);cprintf("                                                                                ");
    gotoxy(1,7);cprintf("                                                                                ");
    gotoxy(1,8);cprintf("                                                                                ");
    gotoxy(1,9);cprintf("                                                                                ");
    gotoxy(1,10);cprintf("                                                                                ");
    gotoxy(1,11);cprintf("                                                                                ");
    gotoxy(1,12);cprintf("                                                                                ");
    gotoxy(1,13);cprintf("                                                                                ");
    gotoxy(1,14);cprintf("                                                                                ");
    gotoxy(1,15);cprintf("                                                                                ");
    gotoxy(1,16);cprintf("                                                                                ");
    gotoxy(1,17);cprintf("                                                                                ");
    gotoxy(1,18);cprintf("                                                                                ");
    gotoxy(1,19);cprintf("                                                                                ");
    gotoxy(1,20);cprintf("                                                                                ");
    gotoxy(1,21);cprintf("                                                                                ");
    gotoxy(1,22);cprintf("                                                                                ");
    gotoxy(1,23);cprintf("                                                                                ");
    gotoxy(1,24);cprintf("                                                                                ");
    gotoxy(1,25);cprintf("                                                                                ");
    
    textbackground(LIGHTBLUE);
    gotoxy(29,13);cprintf("                                  ");
    gotoxy(29,14);cprintf("                                  ");
    gotoxy(29,13);cprintf("                                  ");
    gotoxy(29,16);cprintf("                                  ");
    
    /*outer box*/
    
    textcolor(LIGHTCYAN);
    
    gotoxy(29,11);cprintf("旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴");
    gotoxy(29,12);cprintf("");
    gotoxy(29,13);cprintf("");
    gotoxy(29,14);cprintf("");
    gotoxy(29,15);cprintf("");
    gotoxy(29,16);cprintf("");
    
    /*outer box2*/
    textcolor(BLACK);
    
    gotoxy(62,11);cprintf("");
    gotoxy(62,12);cprintf("");
    gotoxy(62,13);cprintf("");
    gotoxy(62,14);cprintf("");
    gotoxy(62,15);cprintf("");
    gotoxy(30,16);cprintf("컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴");
    
    textcolor(BLACK);
    gotoxy(30,12);cprintf("旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴");
    gotoxy(30,13);cprintf("");
    gotoxy(30,14);cprintf("");
    
    /*outer box2*/
    textcolor(LIGHTCYAN);
    
    gotoxy(61,12);cprintf("");
    gotoxy(61,13);cprintf("");
    gotoxy(31,14);cprintf("컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴");
    
    
    
    
    
                    textcolor(WHITE);
    				gotoxy(35,13);
    				cprintf("Loading Directory System");
    
    
    
    
    					for(x=30;x<62;x++)
    					{
    					textcolor(LIGHTGREEN);
    					gotoxy(x,15);cprintf("");delay(1000000000);
    					}
    
    
    gotoxy(31,13);printf("                             ");
    textcolor(WHITE);
    gotoxy(38,13);
    cprintf("Loading Complete");
    sleep(1);
    
    
    
    
    
    
    }
    The problems missing with this program is
    2.) SORT ENTRY - a.) Sort by first name b.) Sort by surname
    3.) DELETE ENTRY
    a.) Delete whole entry
    b.) delete one entry only
    c.) delete all

    Its due tommorow

    Im sorry for this long post..... its a project and im lost .... i can accept insults here but i can be patient with those advice of yours

    thanks and i apologize.....

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by EdwardElric View Post
    Im sorry for this long post..... its a project and im lost .... i can accept insults here but i can be patient with those advice of yours

    thanks and i apologize.....
    It'd be nice if your code was written before the 1990's and you skipped all the gets()'s, gotoxy's, cprintf()'s, !feof()-controlled loops, and other mainstay pitfalls.

    Are you trying to learn C from some vastly out-of-date Borland-related material? I try not to sound extreme in this matter, but someday you'll have to discard 90% of that code to learn how to do things.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    > Its due tommorow
    Oops - it's too late for us to do much about it then.

    Come back with your next project, and a few days to spare, then we can work on the many real issues with your code.

    > gets(name);
    NEVER use gets(), see the FAQ

    > while(!feof(fp))
    Don't use feof() to control a loop, it doesn't do what you want it to.
    Again, see the FAQ

    > fp=fopen("directory.txt","rb");
    Always check the return result of functions. Also, it's unusual to store binary data in a text file. Many text editors will just blow up if you try to load a binary file pretending to be text.

    > textcolor(BLACK);
    > gotoxy(30,12);cprintf("&#218;&#196;&#196;&#196;&#1 96;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196 ;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;& #196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#1 96;&#196;");
    How much time did you waste creating all this "pretty"?
    How much time did you waste keeping the "pretty" up to date with changes in your other code?

    The first order of business is to get the core code working properly, which you can do with just the standard I/O functions. When (and only when) everything else works do you do a single pass to enhance the presentation.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The use of "goto" is not really conisered a good thing in C. It CAN be used sparingly.

    Your character comparisons, such as this:
    Code:
    while((ch!=72)&&(ch!=80)&&(ch!=13));
    if(ch==72)goto d4;
    if(ch==80)goto d2;
    if(ch==13){select=1;goto down;}
    should be using 'H' and 'P' respectively. [But ah, I think this is the old "function key thingy", where the first character is zero, and the second indicates the scan-code of the key, such as uparrow/downarrow. This should be solved in a different way - perhaps a function that returns an integer that is 0-255 for "normal" keys, and 256..511 for special keys [not that necessarily all of those are used], and then have constants such as "uparrow", "downarrow", that represent the relevant key. ].

    You are also repeating the same section of data many many times - imagine if your menu had 15-20 items in it, you would have to have several hundred lines (at least 225, and with the style you currently have, around 500) of repeats - and the chances of a typo is stupendous at that point.

    You are also putting (large) functions in header files. Header files are for declarations ("Hey, compiler, I'm telling you that I've got a function called box(), you'll find it later"), not for sticking large functions in. If you want to split your project into multiple modules, then you put a box.h with a prototype declaration of "box", then a box.c that contains the actual code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    It'd be nice if your code was written before the 1990's and you skipped all the gets()'s, gotoxy's, cprintf()'s, !feof()-controlled loops, and other mainstay pitfalls.
    It could well be the way the OP was taught to code. My college still uses old Borland compilers, and I was originally told to use gets(), and a load of other bad stuff before I knew any better.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    Don't these colleges / "professors" ever get any feedback from the real world?

    It would be nice to think that once in a while, some past student walked up to them and told them that their course was massively out of date, and was in no way a preparation for a software development career.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    In the "loading" part:
    Code:
    					for(x=30;x<62;x++)
    					{
    					textcolor(LIGHTGREEN);
    					gotoxy(x,15);cprintf("");delay(1000000000);
    					}
    I presume that this is milliseconds as input - and that would make that 1000000 seconds - doesn't sound that much until I tell you that it's 86400 seconds in 24 hours, so a million seconds is about 12 days or so - 32 times 12 days is 364 days. Give or take a year to load - I think I'd be hard pushed to wait so long for any application to start.

    I have no idea how that would work at all, but it's probably some overflow or some such that causes it to only delay a short while.

    Of course, I don't see ANY point in having artificial "loading" code in any application, but it seems like some people feel that it makes the application more professional. Why not spend the time on making the REST of the application code work instead? Or if you MUST have a "loading" part of your project, why not actually LOAD the data into an array, and only save it to disk when necessary.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Salem View Post
    Don't these colleges / "professors" ever get any feedback from the real world?

    It would be nice to think that once in a while, some past student walked up to them and told them that their course was massively out of date, and was in no way a preparation for a software development career.
    To some extent, I agree, but at the same time, if the student learns TO PROGRAM, then it's probably not so important what library functions and stuff they used to learn [but it appears that emphasis isn't on actually learning how to design an applicaiton, but to make it "look pretty" - not repeating my rant about "fake loading stage" here].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 10:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 08:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21