word count in a line
how to find and print only the first word from each line of a file using C programming
|
If you separate words by using only spaces (not tabs, not punctuation, and not any other characters), you could do this:
sed "s/^[ ]*\([^ ]\+\).*/\1/" some_file |
This may be a homework qn (cf: http://www.catb.org/~esr/faqs/smart-....html#homework) ...
However, as hinted by Dark_Helmet, the 1st step is to determine the separator char(s) between words and go from there.... There are several ways of doing this, but personally I'd prob consider the strtok() fn.... depending on the answer to the 1st step qn. |
Code:
#include <stdio.h> |
Hehehe... edited after my response to clarify writing it in C.
It's left as an exercise for the reader to execute shell commands within their program (man popen is a good start). ;) Who knows, it might get a few "creativity points", then again... |
All times are GMT -5. The time now is 02:41 PM. |