generated from freudenreichan/info2Praktikum-Wortsalat
70 lines
1.4 KiB
C
70 lines
1.4 KiB
C
#include "input.h"
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
|
|
// launch
|
|
#define MAX_NUMBER_OF_WORDS 100
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|
{
|
|
char line [MAX_WORD_LEN];
|
|
|
|
int i = 0;
|
|
int j = 0;
|
|
int count = 0;
|
|
file = fopen("words.txt", "r");
|
|
char single_word[MAX_WORD_LEN];
|
|
|
|
while(fgets(line, maxWordCount, file) != NULL ){
|
|
|
|
|
|
while(line[i] != '\0' && line[i+1] != '\0'){
|
|
|
|
|
|
|
|
//prüft, ob das gesammelte Zeichen ein Zeichen ist, schiebt es dann Großgeschrieben in das Array word
|
|
if (isalpha(line[i]) != 0){
|
|
single_word[j++] = toupper(line[i]);
|
|
|
|
}
|
|
// wenn das Wort fertig ist, dann wird dem Wort eine 0 angefügt um das Ende des Strings zu signalisieren, dann wird es in das Array words kopiert
|
|
else{
|
|
single_word[j++] = '\0';
|
|
strncpy(words[count], single_word, i);
|
|
i = 0;
|
|
count++;
|
|
int j = 0;
|
|
}
|
|
i++;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
for(int n = 0; n < count ; n++)
|
|
{
|
|
printf("%s \n", words[n]);
|
|
}
|
|
|
|
}
|
|
|
|
int main()
|
|
{
|
|
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
|
|
FILE*file;
|
|
unsigned int wordCount = 0;
|
|
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
|
|
|
} |