Hello All,
I was wondering which function I would use to accept a line of characters from a user (including spaces) and assign it into an array.
I tried scanf but it terminates when it reads a space. Any help would be appreciated. Thanks
Ross
Hello All,
I was wondering which function I would use to accept a line of characters from a user (including spaces) and assign it into an array.
I tried scanf but it terminates when it reads a space. Any help would be appreciated. Thanks
Ross
How about not. The above is nothing but trouble. So let's stick to fgets where fgets excels and leave scanf to the careful or daring.try
Code:char line[80]; scanf("%[^\n]",line);
My best code is written with the delete key.
scanf() is just a primitive way to get input. If he does not want to get into a complicated fgets() the he doesnt have to. scanf() works fin for me when doing simple things.
--Seph
>scanf() is just a primitive way to get input.
You're turned around, scanf is a very sophisticated function that is not well suited to interactive input.
>If he does not want to get into a complicated fgets()
Maybe I'm just crazy, but which of the following is easier to understand?
Code:scanf ( "%[^\n]", buffer );Which one is easier to check for correctness?Code:fgets ( buffer, sizeof buffer, stdin );
>works fin for me when doing simple things
How do you define simple things? I use scanf when I'm lazy and not writing production code, but only because it makes for convenient numeric conversions and I have to be very careful to do it right. But for any real code I avoid scanf like the plague because it's just too risky and too awkward.
My best code is written with the delete key.