[C PRGM] Get only words from string

Hello

My assignment is to read input file containing a paragraph and store words only in array. I have to get rid of all non-alphabetic characters so that the array ONLY contains words. If a compound word is separated by a dash (-) or any other punctuation mark, that punctuation mark should be removed and the two words should become one word.

Input file:

The, we-ak s#hall ne-ver 4succeed!


Output SHOULD be:

The weak shall never succeed


My code so far:
1
2
3
4
5
6
fpIn = fileInOpen(fpIn);
while (i<MAX&&fscanf(fpIn, "%[^1234567890.!@#$%^&*)_+-=''""]", hold)!=EOF){
    puts(hold);
    strcpy(words[i], hold);
    i++;
}


The code doesn't seem to be working. I know there is something wrong with the while loop. Any help would be appreciated.

Thanks!
there is a isalpha() function in ctype.h
http://en.cppreference.com/w/c/string/byte/isalpha

fgetc would be a better tool for this than fscanf.
hey,
you have gotta store the input file paragraph in a character array.
use isalpha() function to get only alphabets from this input array. and store the output in a new char array(string).remember, 2 words are separated by spaces.
2 words are separated by spaces.
Oh, yes, you will need isspace() too
http://en.cppreference.com/w/c/string/byte/isspace
Topic archived. No new replies allowed.