Situation : suppose we have list of students . And we need to enter their name. As normal no. of character in each name varies . So We can't use looping for storing values in string because looping runs till string size.
Similarly we want to enter space among different words. using normal input functions it's not possible.
Unformatted String Input function
If we want to enter a paragraph where we don't know expected word length then formatted input function we can't use. For this purpose we we following function.
gets() function
int main()
puts() function
int main()
Similarly we want to enter space among different words. using normal input functions it's not possible.
Unformatted String Input function
If we want to enter a paragraph where we don't know expected word length then formatted input function we can't use. For this purpose we we following function.
- gets() for input
- puts() for output
gets() function
We use this function for storing a string value in memory. using this we don't need to use looping. and this function doesn't bound us about memory.
syntex
char str[size];
gets(str);
int main()
{
char str[10];
printf("enter value of str ");
gets(str);
printf("\n value of str is \t ");
printf("%s",str);
printf("\n value of str is \t ");
printf("%s",str);
}
Input enter value of str minty ji
Output value of str is minty
What's this output here. this happen because %s doesn't print after space. So how to handle this situation.
Solution: Use puts() function. This function print every things untill enter character hit.
What's this output here. this happen because %s doesn't print after space. So how to handle this situation.
Solution: Use puts() function. This function print every things untill enter character hit.
puts() function
We use this function for printing a single character value.
syntex
puts(str);
int main()
{
char str[10];
printf("enter value of str ");
gets(str);
printf("\n value of str is \t ");
puts(str);
printf("\n value of str is \t ");
puts(str);
}
Input enter value of str minty ji
No comments:
Post a Comment