0

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 by Nick Evan: Added code-tags, moved thread

4
Contributors
7
Replies
10
Views
6 Years
Discussion Span
Last Post by ToiNKieZ
0

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';
-1
#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.

0

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().

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.