I am trying to read a file and print all of the words that are in the file, ignoring all other spaces and symbols. I have it working with strcpy but it's giving me an error and I'm trying to use sprintf but I don't really understand how that function words. It's printing random integers instead of the strings.
Edit: I'm completely new to C so I don't have my pointers down too well.
FILE *file;
file = fopen("sample_dict.txt", "r");
int c;
int wordcount = 0;
int count = 0;
const char *a[10];
char word[100];
do {
c = fgetc(file);
//error statement
if (feof(file)) {
break;
}
if (isalpha(c) && count == 2) {
printf("%s\n", word);
memset(word, 0, sizeof(word));
count = 1;
wordcount++;
}
if (isalpha(c)) {
//strcat(word, &c);
sprintf(word, "%d", c);
continue;
}
count = 2;
continue;
} while (1);
fclose(file);
return (0);
return 0;