Like Tree1Likes

errors with display function!! Help Plz!!

This is a discussion on errors with display function!! Help Plz!! within the C Programming forums, part of the General Programming Boards category; hi guys, this is 1 function im making as part of a program, it ahs to display info by letting ...

  1. #1
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29

    errors with display function!! Help Plz!!

    hi guys, this is 1 function im making as part of a program, it ahs to display info by letting the user input either an account number or account name and i originally started out with 10 errors but ive managed to half them, i jus cant sem to fix these ones....help would be very much appreciated, i only posted the code needed cos my code is 700 lines long, all of the functions are declared so ive no errors with them, here are the errors and code, i have highlited the errors with ************ i only have 1 error left now i managed to fix 4 of them and the error is the int display menu choice line,

    Code:
    void display_customer_details_name_accountno(CUSTOMER person_array)
    
        
        int diplay_menu_choice *******************************************************************************
        do
        {
            display_menu_choice = menu();
            switch ( display_menu_choice )
            {
                case 1: display_by_account_number(persons);
                        break;
                
                case 2: display_by_name(persons);
                        break;
                }
           
        }
        while ( menu_choice != 0)
        return 0
    
            /*------------------------------------------------------------------------------------/
                    | Function: Display By Account Number Or Name                                    |
                    |                                                                                                            |
                    | Purpose: Display Information                                                               |
                    |                                                                                                            |
                    |                                                                                                            |
                    |--------------------------------------------------------------------------------------*/
        
        
            int display_menu(void)
        {
            int choice 
            
            printf(" Please Choose 1 Of The Following\n"); 
            printf(" 1. Display By Account Number\n");
            printf(" 2. Display By Name And Surname\n");
            printf(" 0. Return To Menu\n");
            
             do
            {
                scanf("%d",&choice); /* when the choice is entered it is taken in and the corresponding function is done according to which number was pressed */
                fflush(stdin);
            } while( choice < 0 || choice > 2 );
          
            return (choice);
    }
    
        void display_by_account_number( CUSTOMER person_array[] )
        {
            int CUSTOMER_number;
            int pos;
            
       
            /* Get The Customer Number */
            printf(" Customer Number To Display ( 1-4 Digits, Except 0) :");
            do
                scanf("%4d",&CUSTOMER_number);
                while( CUSTOMER_number <= 0);
                   
                /* Find The Customer In The Database */
                pos = search_database( person_array,CUSTOMER_number);
               
                /* Does The Customer Exist In The Databse */
                if ( pos == MAX_PERSONS) /* No */
                printf(" The Selected Customer Is Not In The Databse\n" );
                else                     /* Yes - Display The Details */
                    display_customer_details(&person_array[pos]);
            }
            
            void display_by_name(CUSTOMER*ptr)
            
                    {
            char acc_name[50];
            printf("\nEnter the account holder's name: ");
            get_name(acc_name);
            if(acc_name[0] == '\0') return;
            if(!name_check(acc_name))
            {
            printf("\nThat name does not exist!\n");
            return;}
            {
            
            printf("\n\n");
            printf("Account number : %d\n",ptr->number);
            printf("Surname        : %s\n",ptr->surname);
            printf("Firstname      : %s\n",ptr->first_name);
            printf("Occupation     : %s\n",ptr->occupation);
            printf("Surname        : %s\n",ptr->surname);
            printf("Date of Birth  : %2d/%2d/%2d\n",ptr->dob.day, ptr->dob.month, ptr->dob.year);
            printf("Address House Number : %s\n",ptr->ADDRESS.house_number);
            printf("Address Street : %s\n",ptr->ADDRESS.street);
            printf("Address Area : %s\n",ptr->ADDRESS.city);
            printf("Address County : %s\n",ptr->ADDRESS.county);
            }
                
                /*Function get name*/
                void get_name(char *name)
                { 
                int count;
                char temp;
                count=0;
                while ((temp = getch()) != 13)
                {
                if(((temp > 64) && (temp < 91)) || ((temp > 96) && (temp < 123))||(temp == 32))
                {
                putchar(temp);
                name[count]=temp;
                count++;
                }
                if((temp == 8)&&(count > 0))
                {
                putchar(temp);
                putchar(32);
                putchar(temp);
                count--;
                }
                }
                name[count]='\0';
                } 
                
                /*Function name_check*/
                int name_check(char *customer)
                {
                int count;
                for (count=0 ; count < number ; count++)
                {
                if (!strcmp(customer,account[count].name))
                {
                current = count;
                return(1);
                }
                }
                return(0);
            };
    [code] Error E2141 customerdisplay.c 595: Declaration syntax error
    Last edited by irishfeeney92; 05-02-2011 at 09:19 AM. Reason: fixed 4 of the errors

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    These two lines of code require a semi-colon be added at the end of the line:
    Code:
    while ( menu_choice != 0)
        return 0
    After that, you need to add a curly brace after the second line - the function is done.

    It's basically quite well formatted - be sure to keep it that way. It will be difficult to study, otherwise.

    If you have a long comment line, break it up - this "breaks" the forum code width:
    Code:
     /* when the choice is entered it is taken in and the corresponding function is done 
    according to which number was pressed */
    if it's all on one line, after some code on the same row.
    Last edited by Adak; 05-02-2011 at 09:48 AM.

  3. #3
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    hey man thanks, but when i add them semi colons in i get 6 more errors
    Code:
     Error E2141 customerdisplay.c 594: Declaration syntax error
    Error E2040 customerdisplay.c 596: Declaration terminated incorrectly
    Error E2040 customerdisplay.c 610: Declaration terminated incorrectly
    Error E2141 customerdisplay.c 626: Declaration syntax error in function display_menu()
    Error E2141 customerdisplay.c 690: Declaration syntax error in function display_by_name(personnel *)
    Error E2134 customerdisplay.c 726: Compound statement missing } in function display_by_name(personnel *)
    im pretty confused at the moment can u shed any light??

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Obviously, your fix wasn't as much of a fix as you might have thought.

    My regular computer is down with the tld3 rootkit just now, so I'm on a system I'm not too used to (Linux). Let me take a sec and study your code more.

    You also need to add the opening curly brace, right after the very first line of your post:

    Also, remove the 0 on the last line of the first function, because it's a void function.
    Last edited by Adak; 05-02-2011 at 10:18 AM.

  5. #5
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    ok i put the braces in and i took the 0 out, down to 2 errors now thansk for your help btw!!
    these errors are left

    [code]
    Error E2141 mycode2.c 707: Declaration syntax error in function display_by_name(personnel *)
    Error E2134 mycode2.c 743: Compound statement missing } in function display_by_name(personnel *)
    [\code]
    Last edited by irishfeeney92; 05-02-2011 at 10:28 AM. Reason: fixed another error

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    In display_menu(), add a semi-colon at the end of the int choice line of code (first one). Replace the useless fflush(stdin), with getchar() or (void) getchar(), to remove the left over newline that scanf() leaves behind.

  7. #7
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    Quote Originally Posted by Adak View Post
    In display_menu(), add a semi-colon at the end of the int choice line of code (first one). Replace the useless fflush(stdin), with getchar() or (void) getchar(), to remove the left over newline that scanf() leaves behind.
    ok done that still have these two left

    [code]
    Error E2141 mycode2.c 707: Declaration syntax error in function display_by_name(personnel *)
    Error E2134 mycode2.c 743: Compound statement missing } in function display_by_name(personnel *)
    [\code]

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This part is a problem:
    Code:
            return;}
            {
    Unless you REALLY are programming a lot, don't EVER put a curly brace on the end of a line like that - it's just Trouble. Those belong in the same column (vertical), as the opening brace, or the first letter of the line that they refer to:

    Code:
    if(strcmp(yourFormat, "Excellent")== 0)
    {
       printf("\nYou'll have a lot fewer problems with your code\n");
    }

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This formatting is starting to get really ragged - don't do that. Your eye will become trained - as all of ours are, to catch errors in syntax and logic both, just by a quick look at the way the program is laid out.

    If your formatting is junk, it's like trying to run through waist deep snow, up a hill. I'm from Adak, and I know about these things, trust me! <LOL>

    Something like this:
    Code:
            
    void display_by_name(CUSTOMER*ptr)
    {
       char acc_name[50];
       printf("\nEnter the account holder's name: ");
       get_name(acc_name);
       if(acc_name[0] == '\0') return;
       if(!name_check(acc_name))
       {
          printf("\nThat name does not exist!\n");
          return;
       }
       printf("\n\n");
       printf("Account number : %d\n",ptr->number);
       printf("Surname        : %s\n",ptr->surname);
       printf("Firstname      : %s\n",ptr->first_name);
       printf("Occupation     : %s\n",ptr->occupation);
       printf("Surname        : %s\n",ptr->surname);
       printf("Date of Birth  : %2d/%2d/%2d\n",ptr->dob.day, ptr->dob.month, ptr->dob.year);
       printf("Address House Number : %s\n",ptr->ADDRESS.house_number);
       printf("Address Street : %s\n",ptr->ADDRESS.street);
       printf("Address Area : %s\n",ptr->ADDRESS.city);
       printf("Address County : %s\n",ptr->ADDRESS.county);
    }

  10. #10
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    okay ive taken the braces and put it in the right place, still have the 2 errors, my layout is fine on my compiler its jus when i copy and paste it gets bit ........ haha!! i fixed the bracket and it looks like this now


    Code:
       char acc_name[50];
            printf("\nEnter the account holder's name: ");
            get_name(acc_name);
            if(acc_name[0] == '\0') return;
            if(!name_check(acc_name))
            {
            printf("\nThat name does not exist!\n");
            return;
            }

    still have the 2 errors tho

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    In Turbo C, go to Options >> Editor >> and click on the option to have your tabs replaced by spaces. Three to 5 spaces per indent is fine. Uncheck "smart" fill as well - otherwise, you still wind up with some tabs in your code, which the forum software doesn't like.

    Here's what I want you to do:

    1) Fix the damnable format errors. You may relish running through waist deep snow, but I do not.

    2) Study the errors you have, and see if you can find the syntax problems that are causing them.

    3) Re-post your code with the updates, with the correct formatting, if you're still baffled.

    This was a good program at one time, I'm sure. It's clear you need to study it more closely, to understand how it should work.

    And C as well.
    irishfeeney92 likes this.

  12. #12
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    ok ill get back to you, thanks man uve been a great help!!

  13. #13
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    k ive been working on this program the whole day, i almost have it finished but i have 2 errors i cant figure out, when i figure them out the program should be perfect, i also have to make it so that no 2 customers can enter the same account number which is proving difficult

    Code:
            
            void display_by_name(CUSTOMER structarray[])
            
            {
            char name[50];
            char surname[50];
            
            printf("\nEnter the account holder's name: ");
            gets(name);
            printf("Enter the account surname: ");
            gets(surname);
            
            int i=0;
            while(i<MAX_PERSONS)
            if(strcmp(structarray[i].surname,surname)==0 && strcmp( structarray[i].first_name)==0)
            break;
            
            if(i==MAX_PERSONS)
            {
            printf("\nThat name does not exist!\n");
            }
            else
            {
            display_customer_details(&structarray[i]);
            }
    
    
    
            void get_name(CUSTOMER person_array)
            
            printf("Please enter name :");              **************************this is the last error line*********************************
            gets(name);
        }
    
    errors:  
    Error E2268 assignment3A.c 709: Call to undefined function 'strcmp' in function display_by_name(personnel *)
    Error E2141 assignment3A.c 731: Declaration syntax error in function display_by_name(personnel *)

  14. #14
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Do you have the string.h, file included yet?

    If you have prototypes for the functions, be sure the prototype agrees with the display_ by_name function's first line.

    Something's goofy there, but it may be as simple as adding an asterisk somewhere. Haven't had the time to really look at it today - a busy day.
    Last edited by Adak; 05-02-2011 at 05:07 PM.

  15. #15
    Banned
    Join Date
    Apr 2011
    Location
    Santry, Ireland
    Posts
    29
    had to put the
    Code:
     #include<string.h> and a }
    works fine now
    thanks for all your help!!!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Display return value from a function
    By mapleleafblue in forum C Programming
    Replies: 4
    Last Post: 06-30-2009, 01:06 PM
  2. array function errors
    By dantestwin in forum C++ Programming
    Replies: 10
    Last Post: 07-08-2004, 02:48 PM
  3. Function w/ pointer errors
    By pxleyes in forum C Programming
    Replies: 10
    Last Post: 03-18-2004, 10:32 PM
  4. need a display function
    By mattyans in forum C Programming
    Replies: 1
    Last Post: 04-29-2002, 07:41 PM
  5. 'display' function
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 11-27-2001, 04:05 PM

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