Home / C Programming / Strings :: Discussion

Discussion :: Strings

  1. Which of the following function is more appropriate for reading in a multi-word string?

  2. A.

    printf();

    B.

    scanf();

    C.

    gets();

    D.

    puts();

    View Answer

    Workspace

    Answer : Option C

    Explanation :

    gets(); collects a string of characters terminated by a new line from the standard input stream stdin

     #include  
    
     int main(void)
     {   
        char string[80];     
    
        printf("Enter a string:");   
        gets(string);    
        printf("The string input was: %s\n", string);   
        return 0;
     } 
    

    Output:

    Enter a string: FresherGATE

    The string input was:  FresherGATE


Be The First To Comment