+ 1

Accepting unspecified amounts of strings in c

so I have a variable called book name and we know that a person can enter a book name like this "Big Bang Bum" or with two words like "Red Run" or "Wray". I have another variable after and if I decide to enter a book name with 3 parts it messes up the other inputs. So how do we allow it to accept any amount of parts? bookname: jerry joe author: //it skips author because it accepted joe as the input bookid: now asking for this

3rd Dec 2021, 8:09 PM
Jamari McFarlane
Jamari McFarlane - avatar
3 Respuestas
+ 2
Use fgets() function to read an entire line of string input... %s in scanf reads a word of string type only.. #include<stdio.h> int main() { char name[20]; printf("Enter name :"); fgets(name,20,stdin); printf("Name you entered is : %s",name); return(0); } edit: Jamari McFarlane https://www.educative.io/edpresso/how-to-use-the-fgets-function-in-c
3rd Dec 2021, 8:13 PM
Jayakrishna 🇮🇳
+ 1
I am can probably accept the input as RedReadRow instead of Red Read Row but i'd prefer the second way if there is a solution
3rd Dec 2021, 8:10 PM
Jamari McFarlane
Jamari McFarlane - avatar
+ 1
ok thanks..
3rd Dec 2021, 8:27 PM
Jamari McFarlane
Jamari McFarlane - avatar