Template
Compare commits
1
Commits
main
...
feature-input
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4e920ce5b |
@@ -8,5 +8,25 @@
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
if (file == NULL) {
|
||||
return 0;
|
||||
}
|
||||
char line[MAX_LINE_LEN];
|
||||
unsigned int count = 0;
|
||||
|
||||
while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount) {
|
||||
char *token = strtok(line, " ,;\n\r\t");
|
||||
while (token != NULL & count < maxWordCount) {
|
||||
if (strlen(token) > 0) {
|
||||
strncpy(words[count], token, MAX_WORD_LEN - 1);
|
||||
words[count][MAX_WORD_LEN - 1] = '\0';
|
||||
for (int i= 0; words[count][i] != '\0'; i++) {
|
||||
words[count][i] = toupper((unsigned char)words[count][i]);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
token = strtok(NULL, " ,;\n\r\t");
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
Reference in new issue
Block a user