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.