C Programming - Strings - Discussion
Discussion Forum : Strings - General Questions (Q.No. 6)
6.
Which of the following function is more appropriate for reading in a multi-word string?
Answer: Option
Explanation:
gets(); collects a string of characters terminated by a new line from the standard input stream stdin
#include <stdio.h>
int main(void)
{
char string[80];
printf("Enter a string:");
gets(string);
printf("The string input was: %s\n", string);
return 0;
}
Output:
Enter a string: IndiaBIX
The string input was: IndiaBIX
Discussion:
8 comments Page 1 of 1.
Avi said:
9 years ago
Right answer for this question is puts().
(1)
Ozlem sen said:
1 decade ago
I have tried the code in e.g. There is a warning:
Warning: The 'gets' function is dangerous and should not be used.
In function \'main\': \'gets\' is deprecated.
gets(string);
So we must not use the function gets().
Warning: The 'gets' function is dangerous and should not be used.
In function \'main\': \'gets\' is deprecated.
gets(string);
So we must not use the function gets().
(1)
Nandini said:
1 decade ago
Anything which has to be use gets().
Anything which has to be write use puts().
Anything which has to be write use puts().
(1)
Santhoshpendyala484 said:
1 decade ago
Multi-word string means including alphanumeric, and special characters.
(1)
Santhoshpendyala484 said:
1 decade ago
Try this you can get clarify.
#include <stdio.h>
int main(void)
{
char string[80];
printf("Enter a string:");
//gets(string);//scanf("%s",string);
printf("The string input was: %s\n", string);
return 0;
}
#include <stdio.h>
int main(void)
{
char string[80];
printf("Enter a string:");
//gets(string);//scanf("%s",string);
printf("The string input was: %s\n", string);
return 0;
}
Santhosh pendyala484 said:
1 decade ago
If you want to print some text including spaces use gets();
If not use scanf();
Because gets() accepts space as character whereas scanf will not accept.
In scanf function if you press space bar then the execution will terminate.
If not use scanf();
Because gets() accepts space as character whereas scanf will not accept.
In scanf function if you press space bar then the execution will terminate.
Yogesh said:
1 decade ago
What's the exact meaning of multi-word string?
Kamali said:
1 decade ago
What is the main difference between scanf and gets function?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers