Thread: calling a fucntion in a switch operator

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    1

    calling a fucntion in a switch operator

    i just started C and i'm doing a program for a class i'm taking and it requires the usage of a menu (i'm using a switch operator for this) and multiple functions in order to manipulate an image (i.e. load, save, make negative, flip...etc.) i'm having problems calling a function in the switch operator. i keep getting the error: syntax error before fuction...


    any help is greatly appreciated!


    this is what i have so far:
    Code:
    void PrintMenu();
    /* read image from a file */
    int ReadImage(char fname[SLEN], unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT],
    unsigned char B[WIDTH][HEIGHT]);
    /* save a processed image */
    void SaveImage(char fname[SLEN], unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT],
    unsigned char B[WIDTH][HEIGHT]);
    
    /*   begin function PrintMenu   */
    void PrintMenu()
    {
    	int operator;
    	
    	/* begin while loop */
    	while( operator != 11 )	/*  program continues until input of 9   */
    	{
    		printf( "\n1: Load a PPM image" );
    		printf( "\n2: Save an image in JPEG format" );
    		printf( "\n3: Make a negative of an image" );
    		printf( "\n4: Flip an image horizontally" );
    		printf( "\n5: Flip an image vertically" );
    		printf( "\n6: Detect image edges" );
    		printf( "\n7: Add noise to an image" );	
    		printf( "\n8: Image quantization" );	
    		printf( "\n9: Add borders to an image" );	
    		printf( "\n10: Image Overlay" );
    		printf( "\n11: Exit\n" );	
    	
    		printf( "\nEnter your choice:" );
    		scanf( "%d", &operator );
    		
    		
    		switch( operator )
    			{
    			case 1:
    				i get an error here, it says "syntax error before char"-->ReadImage(char fname[SLEN], unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT],
    unsigned char B[WIDTH][HEIGHT]);
    				break;
    			
    			case 2:
    				void SaveImage(char fname[SLEN], unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT],
    unsigned char B[WIDTH][HEIGHT]);
    				break;
    ......and so on.
    please tell me what i'm doing wrong.
    Last edited by Salem; 12-05-2007 at 12:35 AM. Reason: Added code tags, learn to use them!

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Well.. you used a function declaration instead of a function call... Which leads me to think that you don't understand half of your own code because you just pasted something you found on the net. Am I close ?

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    PLEASE USE CODE TAGS

    Code:
    ReadImage(char fname[SLEN], unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT],
    unsigned char B[WIDTH][HEIGHT]);
    This not the way you will call the function. I would really suggest you to look into some basic concepts of on how to call a function. Read this

    You wont be sending the data types of your variable as an argument when calling a function. Instead you would just send the variables as your parameter to the function. Like this

    Code:
    ReadImage(fname, R, G,B);
    ssharish
    Last edited by ssharish2005; 12-04-2007 at 11:21 PM.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    ReadImage() is supposed to return an int per your function declaration. Also, you have a comma on the end of the line.

    Please put your code between [code] and [/code] tags so it is easier to read.

    Todd

    EDIT - yeah, what ssharish2005 said...

  5. #5
    Registered User
    Join Date
    Nov 2007
    Location
    Bangalore, India
    Posts
    24
    Code:
    int operator;
    	
    /* begin while loop */
    while( operator != 11 )	/*  program continues until input of 9   */
    You also need to initialize operator before using it.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by pankaj401 View Post
    Code:
    int operator;
    	
    /* begin while loop */
    while( operator != 11 )	/*  program continues until input of 9   */
    You also need to initialize operator before using it.
    And the comment and the code don't match. Perhaps simply removing the comment would do just as much good? It's not like this bit is extremely difficult to understand.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. operator problems
    By hdragon in forum C++ Programming
    Replies: 10
    Last Post: 12-30-2005, 11:47 PM
  2. overloaded >> operator issue...
    By soulredemption in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2005, 10:53 PM
  3. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 12:55 PM
  4. class initialization and the = operator
    By krygen in forum C++ Programming
    Replies: 3
    Last Post: 01-27-2005, 12:44 AM
  5. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM