Can someone show me a sample code in c which can read in a user inputted sentence/line and then split that line down by white spaces into separate words please? I shall worship you as my new God if someone out there can just show me a sample solution.

6 Years
Discussion Span
Last Post by L7Sqr

Pretty simple to code this up, why not try?

while there are more letters in the string 
  take each letter and put it into a char words[50][50], incrementing j,
  unless it's a space or punctuation char. (use ctype.h and isalnum() ). 
  In that case, increment i and start a new word[i][j] at the next isalnum()
end of while

You know this is painful to not give out code! I always wanted to be a God. ;)

You wouldn't learn much that way, though. Doesn't take a God to figure that out.

Edited by Adak: n/a


By default, operations such as scanf split on whitespace. All that remains is to be able to not overflow buffers and to recognize when the stream has reached an invalid (or empty) state. What exactly are you having trouble with?

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.