How can I take input from user like this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

How can I take input from user like this

Sample Input:  3  Nick Dunburry Tommy Newborne David James

27th Jul 2020, 7:16 PM
Welcome To Hell
Welcome To Hell - avatar
7 Answers
+ 7
char str[100]; int i; for(i=0;i<3;i++) scanf("%[^\n]",str); Like this
27th Jul 2020, 7:28 PM
Welcome To Hell
Welcome To Hell - avatar
+ 7
char str[100]; int i; for(i=0;i<3;i++) scanf("%[^\n]",str); If I go like this and when i=1 in str Tommy Newborne will be stored replacing Nick Dunburry Am I wrong?
27th Jul 2020, 7:44 PM
Welcome To Hell
Welcome To Hell - avatar
+ 6
Initials +50 XP You are given a list of names for a fundraiser, but you need to keep the names relatively anonymous. You are tasked with getting the initials for each name provided. Task: Given a list of first and last names, take the first letter from each name to create initials and output them as a space-separated string. Input Format: The first input denotes the number of names in the list (N). The next N lines contain the list elements as strings. Output Format: A string containing the initials of each name in the original list, separated by spaces. Sample Input: 3 Nick Dunburry Tommy Newborne David James Sample Output: ND TN DJ This is the question
28th Jul 2020, 6:16 AM
Welcome To Hell
Welcome To Hell - avatar
+ 5
No it's 3 name another being sir name
27th Jul 2020, 7:35 PM
Welcome To Hell
Welcome To Hell - avatar
+ 3
How you tried till now about that..?
27th Jul 2020, 7:25 PM
Jayakrishna 🇮🇳
+ 2
Use a 2dimentional charecter array. And read names by scanf("%s", arr[i]) ; where arr is 2d array.. char str[7][100]; int i; for(i=0;i<7;i++) scanf("%s",str[i]); Like this you can have 7 strings.. Edit: Welcome To Hell Is that 3 names or 6? I assumed 6.. So to read entire line: char str[3][100]; int i; for(i=0;i<3;i++) scanf("%[^\n]",str);
27th Jul 2020, 7:31 PM
Jayakrishna 🇮🇳
+ 2
Yes. By that way you specified, it replaces with next input.. You need to Use a 2dimentional charecter array, as I specified.. First read N. You can go with reading single word by %s, then read N*2 words and just print first letters... Or Read entire name, by looping N times only.. Then you need print 1st letter + letter after a space.. This can done by loop or by strtok..
28th Jul 2020, 2:21 PM
Jayakrishna 🇮🇳