Another C question by the newb | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Another C question by the newb

If I want to accept a number from a user to determine how many strings I will then accept for example: 3 Bob A Mike B Charlie C How can I do that allowing the number to be variable and define the rest of the input?

9th Jan 2020, 2:17 AM
Shay Christensen
Shay Christensen - avatar
5 Answers
+ 1
I am also a C newb :) And I tried to implement this now on my own, by the time I finished you already had the answer :) I used a 2d char array though.. Coder Kitten I assume you proposed a struct to store the firstname and the letter separately, as in the example "Bob A"? https://code.sololearn.com/cf23Ci3gNpHm/?ref=app
9th Jan 2020, 5:56 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Ok with your help put this together and it worked! https://code.sololearn.com/cdFmjWcGoXhG
9th Jan 2020, 8:08 PM
Shay Christensen
Shay Christensen - avatar
0
thanks for your help i was making the mistake of using %s\n only and thinking it would grab the name and initial!
9th Jan 2020, 5:10 AM
Shay Christensen
Shay Christensen - avatar
0
i prefer fgets too. could i iterate through fgets for n number of times? would that even work?
9th Jan 2020, 5:16 AM
Shay Christensen
Shay Christensen - avatar
0
i like it! thanks a million
9th Jan 2020, 5:19 AM
Shay Christensen
Shay Christensen - avatar