input.c fertig 2 und game.c ins terminal geprintet

This commit is contained in:
Ben Skuppin 2025-11-04 11:45:32 +01:00
parent d5539e08b8
commit ef907a5662
2 changed files with 29 additions and 8 deletions

View File

@ -62,5 +62,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
// Prints the word salad to console // Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{ {
printf("WORTSALAT:\n\n");
for (int i = 0; i < searchFieldLen; i++) {
for (int j = 0; j < searchFieldLen; j++) {
printf("%c ", salad[i][j]);
}
printf("\n");
}
} }

View File

@ -12,11 +12,24 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
char text [2000]; char text [2000];
char line[200]; char line[200];
int i = 0; int i = 0;
int textcount = 0;
int counter = 0;
char *token;
while (fgets(line, sizeof(line), ptr)) { while (fgets(line, sizeof(line), file)) {
for (int j = 0; line[j] != '\0'&& i < sizeof(text)-1;j++) { for (int j = 0; line[j] != '\0'&& i < sizeof(text)-1;j++) {
text[i++] = line[j]; text[i++] = line[j];
textcount++;
if (textcount>1999) {
break;
}
}
if (textcount>1999) {
printf("Textdatei zugross!!!");
return 1;
} }
} }
@ -29,25 +42,25 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
const char *trenner = ",; \n"; const char *trenner = ",; \n";
token = strtok(text, trenner); token = strtok(text, trenner);
while (token != NULL) { while (token != NULL&& counter < maxWordCount) {
strncpy(words[zaehler], token, MAX_WORD_LEN - 1); strncpy(words[counter], token, MAX_WORD_LEN - 1);
words[zaehler][MAX_WORD_LEN - 1] = '\0'; words[counter][MAX_WORD_LEN - 1] = '\0';
token = strtok(NULL, trenner); token = strtok(NULL, trenner);
zaehler++; counter++;
} }
maxWordCount=zaehler;
//alle Buchstaben in Großbuchstaben ändern //alle Buchstaben in Großbuchstaben ändern
for (int h = 0; h < zaehler; h++) { for (int h = 0; h < counter; h++) {
for (int check = 0; words[h][check] != '\0'; check++) { for (int check = 0; words[h][check] != '\0'; check++) {
if (words[h][check] >= 'a' && words[h][check] <= 'z') { if (words[h][check] >= 'a' && words[h][check] <= 'z') {
words[h][check] -= 32; // direkt ins Array schreiben words[h][check] -= 32; // direkt ins Array schreiben
@ -56,5 +69,5 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
} }
return 0; return counter;
} }