String I/O Functions:


The gets ( ) and puts ( ) are the string I/O library functions available in C, that permit some form of data transfer into or print on monitor.

The gets ( ) and puts ( ) are analogous to scanf ( ) and printf ( ) for reading and displaying strings. This string may even include whitespace characters.

In case of gets ( ), the string will be entered from the keyboard and will terminate with a newline character ( \n).

If  a space is encountered, it will be treated as a character and it will continue further operation.
But in case of scanf ( ), when we use %s as a control character space will not be treated as a special character and it will result in termination of that string. Any character (s) entered after that would not be stored in that variable.

#include<stdio.h>
#include<conio.h>
main ( )
{
            char name[10];
            scanf (“%s”,name);
            printf( “\n %s”,name);
}

When the scanf ( ) function executed and user inputs a string WWE Wrestling then only the string WWE is stored in the variable name. The string Wrestling after blank space is discarded.
Therefore, when the contents of variable name are printed using printf ( ) function then only new is printed.

To use gets  ( ) and puts ( ) to enter and print your name.
#include<stdio.h>
#include<conio.h>
main()
{
            char ch[20];
            gets(ch);
            puts(ch);


Previous                                                                                   Next

Powered by Blogger.