forked from freudenreichan/info2Praktikum-Wortsalat
Polish
This commit is contained in:
4 files changed
+23
-11
No files matched your search
+15
-4
@@ -1,22 +1,33 @@
|
||||
#include "input.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
int readWord(char *buffer, char *divisor, char words[][MAX_WORD_LEN], unsigned int maxWordCount, int *count);
|
||||
void toUpperCase(char *word);
|
||||
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
unsigned int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
char buffer[MAX_LINE_LEN];
|
||||
int count = 0;
|
||||
unsigned int count = 0;
|
||||
char *divisor = " ,;.\n";
|
||||
|
||||
while (fgets(buffer, MAX_LINE_LEN, file) != NULL)
|
||||
{
|
||||
for (char *word = strtok(buffer, divisor); word != NULL && count < maxWordCount; word = strtok(NULL, divisor))
|
||||
{
|
||||
strncpy(words[count], word, MAX_WORD_LEN);
|
||||
strncpy(words[count], word, MAX_WORD_LEN - 1);
|
||||
words[count][MAX_WORD_LEN - 1] = '\0';
|
||||
toUpperCase(words[count]);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void toUpperCase(char *word)
|
||||
{
|
||||
for (int i = 0; i < strlen(word); ++i)
|
||||
{
|
||||
word[i] = toupper(word[i]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user