Make the difference..

what is the difference between scanf("%s",str)and gets(str), where str is a char pointer which is allocated memory?

Comments

  • : what is the difference between scanf("%s",str)and gets(str), where str is a char pointer which is allocated memory?
    :

    The first statement with scanf() stores all the characters entered until it finds a space character (space characters include space, newline, tab). gets() stores all the characters until it finds a newline.

    For example, with the input string "Hello world!
    ", if the statement with scanf() is used, then str will contain "Hello"; if the statement with gets() is used, str will be "Hello world!".

    Steph
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion