Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (mica):

C. how do i print out a sentence that the user typed in? so far this is what i have char sent[100]; printf("type a short sentence: "); scanf("%s", sent); prtinf("%s", sent); problem is it only print out the first word =/

OpenStudy (espex):

The reason it is only capturing the first word is because scanf only reads up to the first whitespace or newline. You can try doing something like: scanf("%[^\t\n]s", sent);

OpenStudy (anonymous):

you may also use fgets(), a nice alternative to scanf() if you need to get strings: http://www.cplusplus.com/reference/clibrary/cstdio/fgets/ fgets reads until you enter a newline, until EOF is reached, or until n-1 characters (n is the second argument to fgets) have been read so it should accept tabs and spaces http://ideone.com/2XKhZ

OpenStudy (anonymous):

Make sure you specify "stdin" as the stream to pick up what the user types in, and make sure the the string is big enough for whatever limit you prescribe.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!