Originally Posted by
Elysia
You need to separate declarations and definitions, initializations.
First, you must tell the compiler how the actual struct looks like - ie, no initialization. Just tell the compiler how the struct looks like, how the array looks like, and so on.
When creating an object of that struct type, THAT is where you need to put the data you want into the struct.
.
is this what you mean?
Code:
struct airline {
int seats[12];
char customer[BUFSIZ];
};
char showmenu ( void ); // proto functions //
void shownumber ( struct airline nos );
int main(int argc, char *argv[])
{
struct airline seats[12] = { 1,2,3,4,5,6,7,8,9,10,11,12 };
also i want to pass in the array of seats to a function so i can print it out!
how can i do this.. it dont work i get a
error of
31 C:\Dev-Cpp\airlines.c incompatible type for argument 1 of `shownumber'
Code:
struct airline {
int seats[12];
char customer[BUFSIZ];
};
/**********************************************/
char showmenu ( void ); // proto functions //
void shownumber ( struct airline nos );
/*******************************************/
/******************** MAIN******************************/
int main(int argc, char *argv[])
{
struct airline seats[12] = { 1,2,3,4,5,6,7,8,9,10,11,12 };
char choice;
while ( ( choice = showmenu() )!= 'f' ) // loop for menu
{
switch ( choice )
{
case 'a' : shownumber ( seats );
break;
case 'b' : printf(" you hit b");
break;
}
system("PAUSE");
return 0;
}
}
/*********************** MENU FUNCTION *****************************/
char showmenu ( void )
{
char ans;
printf(" ********** Welcome to Swift Lines Airlines ************\n");
printf("\n ********** To Choose A Function, Enter its Letter Label:\n");
printf("\na ) Show Number of seats\n");
printf("b ) Show List of seats\n");
printf("c ) Show alphabetical list of seats\n");
printf("d ) Assign a Customer to a seat assignment\n");
printf("e ) Delete a seat assignment\n");
printf("f ) Quit\n");
ans = getchar();
ans = tolower( ans );
while ( strchr ( "abcdef" , ans ) == NULL )
{
puts( " please pick a - f :\n");
ans = tolower( getchar() );
}
return ans;
}
/********************** END MENU FUNCTION *************************/
void shownumber ( struct airline nos[] )
{
int x;
for ( x = 0 ; x < 12; X++ )
{
printf ( " swift Lines seats-- %d" , nos->seats );
}
}