Thread: Function Return

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    41

    Post Function Return

    How would you return a space from say an if else statement?
    Code:
    int x;
    char ' ';
    if (x>0)
    winner = 'x'
    printf("winner is %d\n",winner);
    else 
    winner = ' ';
    printf("winner is %d\n", winner);

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    First, this means nothing:
    Code:
    char ' ';
    For the function, you would declare the function as returning a char, and then in the function, return the char:

    Code:
    char foo() {  
       return 'b' ; 
    }
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    if if/else or other block contains more than 1 statement you have to use braces, for one statement blocks it is recomended to use braces
    Code:
    if(x)
    {
       ch = ' ' ;
    }
    else
    { 
       ch = 'x';
       ch++;
    }
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. 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