Gets() function
The multiple words string using the gets( ) function
Because the scanf( ) function will get terminated by pressing the space.
But if you want to read the multiple words string , we have to make use of the gets( ) function.
gets( ) : This function is present in the header file stdio.h and is used to read the string which can even contain the spaces. Thus, the gets( ) will get terminated only by pressing the enter.
The general form is , gets(string name);
Consider the following program,
#include<stdio.h>
#include<conio.h>
void main( )
{
char s[50];
clrscr( );
printf("\nEnter the string :");
gets(s);
printf("\nYour string : %s",s);
getch();
}
output :
Enter the string : computer science
Your string : computer science
In "C" programming language , we are provided with a separate file "string.h" which will be used for the string handling.
It contains various pre-defined functions , which will used for manipulating the strings.
Comments
Post a Comment