Hi, Im undergoing a project at the moment and have stumbled onto an error which a could solve nor understand even with google help...
So, the C program Im making is suppose to sort an array of surnames into alphabetical order, also the user can use the menu to pick an option of he/she wants to do in the program.
This is only a snippet of the actual program which Im writing, and so i have stripped it so that it wouldnt contain to much irrelevant code for this problem.

This is the code :

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define SIZE 5

    
struct bank_account             //where acc details will be stored.
{
    DATE dob;
    char *account_array[SIZE];
    int number, sort;            //number = acc.number; house = house.number; sort = sort.code.
    char surname[26];   // Strings for Name, Surname .    
};
typedef struct bank_account ACC;    
    
    void init_database(ACC[]);
    void display_an_account(ACC *);         //search na display an account with its details.
    void display_account_details(ACC[]);     
    void display_an_account(ACC *);         //search na display an account with its details.
    void display_account_details(ACC[]); 
    void display_all(ACC[]);                //display all account with their details.
    void sort_surname(ACC[],char *); 

int menu(void);         //where the main menu is shown
void search_menu();     //Menu in which searching options are displayed

void main()             //main program
{
        ACC number[SIZE];  //brings number[array] and surname[string] into the menu
        int menu_choice;                //initialise  the menu choice
        
        init_database(number);          //initialises everything to zero(empty)
        
    do                                  //Main Menu of the program
    {
            menu_choice = menu();       //swaps the menu() function into menu_choice
            
        switch (menu_choice)
        {
            case 1:
                
                display_all(number);
                break;
            case 2:
                sort_surname(number);Where it points to an error
                break;
        }
    }
        while (menu_choice !=0); //To exit the programm enter zero
}

 void display_account_details(ACC *ptr)
    {           /*Displays the infrmation of the account*/
            printf("\n\n");
            printf("\t +------------------------------+\n");
            printf("\t |Account Number  : %d\n         ",ptr->number);
            printf("|Surname            : %s\n         ",ptr->surname);
            printf("+------------------------------+");
            printf("\n\n");
    }
    
void display_all (ACC account_array[]) 
        {
            int hold, i;
            for(int pass = 1; pass < SIZE; pass++)
            {
                for(i = 0; i < SIZE-1; i++)
                {
                    if(account_array[i].number > account_array[i+1].number)
                    {
                         hold = account_array[i].number;
                        account_array[i].number = account_array[i+1].number;
                        account_array[i+1].number = hold;
                    }
                }
            }
      
                    printf("\n\nResult\n");
                for(int i = 0; i < SIZE; i++)
                    printf("%4d",account_array[i].number);
            
        if (i == SIZE)
            printf("This Account doesn't exist\n");
        else
            display_account_details(&account_array[i]);
                
        }
        
        
        
    void sort_surname(ACC,char *account_array[])
        {
            
            int i,j;
            char* temp;
            
            for(i=0; i<SIZE;i++)
            {
                
                for(i=0;i<SIZE-1;i++)
                for(j=i+1; j<SIZE; j++)
                if (strcmp(account_array[i], account_array[j])>0)
                { 
                    temp = account_array[i];
                    account_array[i] = account_array[j];
                    account_array[j] = temp;
                   
                }
            }
            for(i=0;i<SIZE; i++)
            printf("\n %s",account_array[i]);
        }
        
         void init_database(ACC account_array[])
    {
            int i;
        
        for(i=0; i< SIZE; i++)          //increments the index until the end of the array
            account_array[i].number= 0; //sets the number to 0
    }

This is the error which i cant solve:

Error E2193 test_ass.c 50: Too few parameters in call to 'sort_surname(bank_account *,char *)' in function main()

I think that the error is not the line to which it is pointing to..
Many thanks.

Hello drongo,
In your function calling you didn't mention all the parameters. You didn't give the char* parameter.

Sorry for stupidity, but i don't fully understand what am I suppose to add.
Also what do you mean by "mention all parameters", do I have to give char* parameter to the 'sort_surname(number)' in the switch statement or is it into some other place?
thanks.

Yes, in the switch case function an array is not passed as a parameter sort_surname ( number, /* *string */ );
And in the function definition of sort_surname object has not been declared. I wonder how come you haven't got any errors?

void sort_surname(ACC,char *account_array[])//here the object should have been declared
commented: THANKS +0

Thanks, I have the string passed in the switch statement like this : sort_surname(number, *account_array);
So, now it shows me this

Error E2451 test_ass.c 51: Undefined symbol 'account_array' in function main()
Of course i have tried to understand the error and solve it, with no success unfortunately OR did i miss understood where you were trying to point me to.

It's giving that error because *account_array is not declared in main(). Keep in mind that the parameter is *account_array[]. So you should declare it appropriately.

I did after i posted the comment. I declared it as char *account_array, which brought me to another set of errors

Error: Unresolved external 'menu()' referenced from C:\USERS\CLASSIC\DOCUMENTS\PROGRAMMING\TEST_ASS.OBJ
Error: Unresolved external 'sort_surname(bank_account *, char *)' referenced from C:\USERS\CLASSIC\DOCUMENTS\PROGRAMMING\TEST_ASS.OBJ

can you post the modified code?

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define SIZE 5

struct date
{
    int day, month, year;       //initialise for day,year,month.
};
typedef struct date DATE; 
    
struct bank_account             //where acc details will be stored.
{
    DATE dob;
    //char *account_array[SIZE];
    int number, sort;            //number = acc.number; house = house.number; sort = sort.code.
    char surname[26];   // Strings for Name, Surname .    
};
typedef struct bank_account ACC;    
    
    void init_database(ACC[]);
    void display_an_account(ACC *);         //search na display an account with its details.
    void display_account_details(ACC[]);     
    void display_an_account(ACC *);         //search na display an account with its details.
    void display_account_details(ACC[]); 
    void display_all(ACC[]);                //display all account with their details.
    void sort_surname(ACC[],char *); 

int menu(void);         //where the main menu is shown
void search_menu();     //Menu in which searching options are displayed

void main()             //main program
{
        ACC number[SIZE];  //brings number[array] and surname[string] into the menu
        char *account_array[SIZE];
        int menu_choice;                //initialise  the menu choice
        
        init_database(number);          //initialises everything to zero(empty)
        
    do                                  //Main Menu of the program
    {
            menu_choice = menu();       //swaps the menu() function into menu_choice
            
        switch (menu_choice)
        {
            case 1:
                
                display_all(number);
                break;
            case 2:
                sort_surname(number, *account_array);
                break;
        }
    }
        while (menu_choice !=0); //To exit the programm enter zero
}

 void display_account_details(ACC *ptr)
    {           /*Displays the infrmation of the account*/
            printf("\n\n");
            printf("\t +------------------------------+\n");
            printf("\t |Account Number  : %d\n         ",ptr->number);
            printf("|Surname            : %s\n         ",ptr->surname);
            printf("+------------------------------+");
            printf("\n\n");
    }
    
void display_all (ACC account_array[]) 
        {
            int hold, i;
            for(int pass = 1; pass < SIZE; pass++)
            {
                for(i = 0; i < SIZE-1; i++)
                {
                    if(account_array[i].number > account_array[i+1].number)
                    {
                         hold = account_array[i].number;
                        account_array[i].number = account_array[i+1].number;
                        account_array[i+1].number = hold;
                    }
                }
            }
      
                    printf("\n\nResult\n");
                for(int i = 0; i < SIZE; i++)
                    printf("%4d",account_array[i].number);
            
        if (i == SIZE)
            printf("This Account doesn't exist\n");
        else
            display_account_details(&account_array[i]);
                
        }
        
        
        
    void sort_surname(char *account_array[])
        {
            
            int i,j;
            char* temp;
            for(i=0; i<SIZE;i++)
            {
                
                for(i=0;i<SIZE-1;i++)
                for(j=i+1; j<SIZE; j++)
                if (strcmp(account_array[i], account_array[j])>0)
                { 
                    temp = account_array[i];
                    account_array[i] = account_array[j];
                    account_array[j] = temp;
                   
                }
            }
            for(i=0;i<SIZE; i++)
            printf("\n %s",account_array[i]);
        }
        
         void init_database(ACC account_array[])
    {
            int i;
        
        for(i=0; i< SIZE; i++)          //increments the index until the end of the array
            account_array[i].number= 0; //sets the number to 0
    }

In line 97 it seems that you have removed the parameter for structure, but you are passing a structure in the line 51. Check that out.

O.K. i have returned the parameter

void sort_surname(ACC, char *account_array[])

and still get those errors.

Give some object in the declaration.
For example..

sort_surname(ACC obj[],char *account_aray);

But i see that you are not using the any object in the function sort_surname(). So remove the parameter in the declaration and don't pass any structures in line 51.

case 2:
      sort_surname(account_array);//not the number parameter
      break;

In the function ..

void sort_surname(char *account_array[]);

Hope this helps.

When do the way you tell me. i get
Error E2034 test_ass.c 51: Cannot convert 'char * *' to 'char *' in function main()
Error E2340 test_ass.c 51: Type mismatch in parameter 1 (wanted 'char *', got 'char * *') in function main()
Warning W8080 test_ass.c 56: 'account_array' is declared but never used in function main()
But when i change account array into non-contant

sort_surname(*account_array);

it gives me the same errors

In your code the declaration of the pointer account_array is fine.

char (account_array[size];

Your function declaration is also fine.

void sort_surname(char *account_array[])

The mistake lies in the function calling in line 51.

sort_surname(number, *account_array);

Here you have passed structure, but in your function you didn't have any parameter to get structure.
So it should have been

sort_surname(account_array);

In your code the declaration of the pointer account_array is fine.

char (account_array[size];

I guess you meant

char *account_array[size];

I guess you meant
C Syntax (Toggle Plain Text)
char *account_array;

Yeah, sorry that's due to my poor typing.

If i remove the '*' from the line 51 and leave the declarations char* i get.
Error E2034 test_ass.c 51: Cannot convert 'char * *' to 'char *' in function main()
Error E2340 test_ass.c 51: Type mismatch in parameter 1 (wanted 'char *', got 'char * *') in function main()
Warning W8080 test_ass.c 56: 'account_array' is declared but never used in function main()
doesnt that mean that it requires the '*' in the line 51 or declraing just as char and not char*?
Thanks.

It gives those errors because you didn't change the prototype for sort_surname()
The prototype should be

void sort_surname(char**);/* not that the parameter Acc[] is not given*/

Finally, Thanks a lot Arbus. It was a big help you gave me!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.