Function Return

This is a discussion on Function Return within the C Programming forums, part of the General Programming Boards category; How would you return a space from say an if else statement? Code: int x; char ' '; if (x>0) ...

  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
    Katy, Texas
    Posts
    2,309
    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' ; 
    }
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    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++;
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 12: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, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21