+ 2
If i give space in my input it does not shows next words
#include <stdio.h> int main() { char a[100]; scanf("%s",a); printf ("you entered: %s",a); return 0; }
7 ответов
+ 7
String is an array of characters in C so there is no need to put & before array a in scanf
scanf("%s", a) ;
edit:
%s accepts only single word. To accept line of string, use fgets()
+ 4
You can use fgets() to read input string with spaces included. scanf() can also do something similar, but it's a little bit more tricky.
http://www.cplusplus.com/reference/cstdio/fgets/
+ 4
Adil Shaikh
Don't edit the original question. You can make another question instead.. Otherwise it confuses the readers.. and answer may not match as mine.
%s accepts single word only... To accept entire line of string, use fgets() function or by scanf as
scanf("%[^\n]", a); // accepts entire line (edited)
Or
fgets (a, 100,stdin) ; // input into array a, max length 100 from stdin.
#include <stdio.h>
int main() {
char a[100];
scanf("%[^\n]",a);
printf ("you entered: %s",a);
return 0;
}
edited..
+ 3
scanf("%[^\n]", a); .....this will allow you to enter a single line of text until it find a new line character (when you press "enter").
scanf("%[^*]", a); .... this will allow you to enter multi line text until if find a " * " and then you press "enter".
0
Otherwise use for loop
0
H
0
What?