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.

Recommended Answers

All 2 Replies

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

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.