Use of gets() function?

Use of gets() function?

Senior Developer Asked on February 11, 2017 in C.
Add Comment
1 Answer(s)

    The function gets() reads a line from stdin and stores them as a string into str until a newline character or the end-of-file is reached.

    
    gets( <your variable-name> )
    
    

    Demo code:

    
    #include <stdio.h>
    
    int main()
    
    {
    
    char str[100];
    printf("Enter a website url: ");
    
    gets(str);
    printf("Website url: %s", str);
    return(0);
    
    }
    
    

    Result of the above program:

    
    Enter a website url: http://avianceschool.com
    
    Website url: http://avianceschool.com
    
    
    Senior Developer Answered on February 22, 2017.
    Add Comment

    Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.