Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple word string input through scanf( )

Tags:

c

what was the syntax to input strings with more than one word i.e with space in between through scanf() not gets()

like image 608
prithu Avatar asked Aug 24 '10 09:08

prithu


People also ask

How do I input multiple strings in Word?

char name[50]; printf("Enter your full name: "); scanf("%[^\n]",name); The %[^\n] conversion asks scanf( ) to keep receiving characters into name[ ] until a \n is encountered. It's a character-set, and starting with ^ means accept anything but that.

Can scanf take multiple inputs?

Inputting Multiple ValuesIf you have multiple format specifiers within the string argument of scanf, you can input multiple values. All you need to do is to separate each format specifier with a DELIMITER - a string that separates variables.

How do you accept a multi word in C?

Input a multi-word string using scanf() To overcome this, we need to use the format specifier, “%[^\n]s” . This means that the program will receive all the words in the string, from the beginning up to a \n . scanf("%[^\n]s", stringName); main.

What is multi word string in C?

The function gets() is used for collecting a string of characters terminated by new line from the standard input stream stdin. Therefore gets() is more appropriate for reading a multi-word string.


1 Answers

Is it

scanf("%[^\t\n]",string);
like image 147
Chubsdad Avatar answered Oct 20 '22 20:10

Chubsdad