Well we have already discussed about the usage of ‘fflush’ statement, let us now discuss about the usage of ‘gets’ statement. String is an array of characters and we use the format specifier ‘%s’ to directly get these array of characters, which is not possible in the case of array of integers. In the case of array of integers we use the ‘for’ loop to get the values since we don't have any format specifier for array of integers.
To get array of characters we use the format specifier ‘%s’ as shown below
puts(“Enter the string”);
scanf(“%s”,ex_str);
puts(ex_str);
Enter a string
sample text
sample
puts(“Enter a string”);
gets(ex_str);
puts(ex_str);
Enter a string
sample text
sample text
Just think of getting a name of a person which contains first name, last name and middle name so this ‘gets’ statement is much useful in those situations. Happy Programming!!