+ 1

how to use scanf to input charecters "hello world"

4th Dec 2019, 11:22 AM
badal jha
badal jha - avatar
4 Réponses
+ 2
badal jha it should be like scanf("%[^\n]s", char) It will keep taking input until it doesn't encounter any new line[Enter key].
4th Dec 2019, 11:46 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
what if i use scanf("%[^\n]",char) is it works?
4th Dec 2019, 11:31 AM
badal jha
badal jha - avatar
+ 1
you can use this code to input and print any character string or character array using scanf() But as Avinash said gets() is better and easy. https://code.sololearn.com/cfK3B8W8y3fX/?ref=app
4th Dec 2019, 11:51 AM
Pradeep Kumar Prajapati
Pradeep Kumar Prajapati - avatar
- 1
You cannot use scanf to take a string type as long as it is more than 1 word. May be you can use gets(). Edit: Sorry wasn't aware of the solution others mentioned.
4th Dec 2019, 11:29 AM
Avinesh
Avinesh - avatar