Thread: Problems with a function...please help

  1. #1
    Registered User Vireyda's Avatar
    Join Date
    Mar 2004
    Posts
    26

    Question Problems with a function...please help

    Hello all,

    I'm having trouble with this section of my code. My program produces an illegal error and then ends before it will call to either of the functions FirstClass or Economy. Can anyone tell me where I might ahve gone wrong with this and how to get it to work? (code below)

    Thanks,
    Vireyda

    Code:
    void Assign(int A[])
    	{
    	char seatclass;
    	do
    	{
    	printf("\nWill the passenger be flying first class or economy class?\nFirst class\t- F or f\nEconomy class\t- E or e\n");
    
    	fflush(stdin);
    	scanf("%c", seatclass);
    	switch(seatclass)
    	{case 'F':case 'f':
    		FirstClass(A);
    		break;
    	case 'E': case'e':
    		Economy(A);
    		break;
    	default:
    		printf("\nThat is an invalid seat class.  Please try again.\n");
    	}//end switch
    	}while(seatclass!='E'&&seatclass!='e'&&seatclass!='F'&&seatclass!='f');

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    	scanf("%c", seatclass);
    scanf() takes a pointer to the location where you want the result. This usually means the address of a variable.

    Examples:
    Code:
    	scanf("%c", &seatclass);
    	scanf("%f", &myfloat);
    	scanf("%s", mystring); // A string is already a char *
    Most C functions that return a value through an argument follow this rule.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Problems with str.replace function
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 03:35 AM