Help!! how do you do this in turboC?
when i add a space it doesnt show the following output

example:

char name[50]

printf("enter your name: ); (user input example is: Boris Ilyanovich Karpov)
scanf("%s", &name);

printf("%s", name); (the output is just: Boris)

how do i get the following Ilyanovic and Karpov to show up with the Boris???
help... newbie here...

output should be: Boris Ilyanovich Karpov...

how do i do that...? can somebody show me a code

Edited 6 Years Ago by Nick Evan: Added code-tags, moved thread

scnaf(%s stops processing keyboard input when it encounters the first space. If you want to include space when use fgets() instead of scanf()

fgets(name, sizeof(name), stdin);
// now remove the trailing carrage return '\n'
if( name[strlen(name)-1] == '\n')
   name[strlen(name)-1] = '\0';
#include <stdio.h>
int main(void)
{
   char string[80];
   printf("Input a string:");
   gets(string);
   printf("The string input was: %s\n", string);
   return 0;
}

Use gets() in place of scanf() take without space.
Best Of Luck.

Never, ever, for any reason, use gets() because it will net you corrupt the entire program. That's why I (and everyone else who has half a brain) use fgets().

Your solutions has been very helpful... thanks a lot... by the way... can you recommend any good C++ books as a guide for newbies....? thanks in advance...

This article has been dead for over six months. Start a new discussion instead.