saving . . . saved not reading the string value.. has been deleted. not reading the string value.. has been hidden .
not reading the string value..
Title
Question
#include<stdio.h>
//#include<string.h>
void main()
{
  int n;
  char str[20];  //={"am string"};
  printf("Enter a number");
  scanf("%d",&n);
  printf("Enter a String");
  scanf("%[^\\n]s",str);
  printf("The Number You entered is: %d\\n",n);
  printf("The String You entered is: %s\\n",str);

C-and-Cpp Strings 04-05 min 0-10 sec 29-02-20, 4:09 p.m. SudheerSharma

Answers:

You should do scanf("%s", str) to read a string
29-02-20, 4:40 p.m. bhaskar76


scanf("%d",&n);
fflush(stdin);
printf("Enter a String");

After entering number n when you pressed ENTER key it is taken as String Input So you are not able to enter string value on the output screen.
The solution: To clean the standard input stream use fflush(stdin).
01-03-20, 10:22 a.m. kapilshukla2006


In line 2, // is added. Hence, "string.h" is not included in file, instead it had became comment.
21-06-21, 5:41 p.m. Sujan_A_T


Log-in to answer to this question.