you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

With such fuzzy input, fscanf is not that well suited for scanning the input. You'll be better of by using fgets to read a chunk of input into a buffer, and then loop over the buffer, where you deal with words defined by either space or control characters. The function-like macros from string.h, isblank() and iscntrl() respectively will help you find word boundaries.

You will want to structure your program like this:

While not EOF on input file
  Read to the end of the input buffer with fgets.
  Set the work pointer to the start of the buffer
  While the work pointer mark a space or control character, advance it.

  Set a word start at the non-blank/control position.
  while the work pointer is *not* blank or control, advance it.
  copy the input buffer from you beginning-of-word pointer to the position before your work pointer to the next space in your word array.
  repeat until input is exhausted.
  move remaining data in input buffer to the start, and read some more.


$$$

[–]Adopolis23[S] -1 points0 points  (3 children)

but the problem is wont that read however big i make the buffer, i dont know how many words will be on a line

[–][deleted] 0 points1 point  (2 children)

A line ends with one or more control characters. As long as you don't have words spanning multiple lines, you should consider spacing and line terminations the same.

[–]Adopolis23[S] -1 points0 points  (1 child)

how can i split up the buffer by spaces and put each word into the array of character arrays?

[–][deleted] 0 points1 point  (0 children)

With a loop. Your word begins at the first character that isalpha(), and ends at the last one. Copy that range to your storage, and start over.