input . c unvollständig

This commit is contained in:
Luis Gessnitzer 2025-11-04 09:12:06 +01:00
parent a413f8fe7f
commit 405ffbd805

View File

@ -6,26 +6,36 @@
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// Read words from file and store in 'words' array // Read words from file and store in 'words' array
// f gets ; komma und semikolon erkennen und alles in groß buchstaben (=uppercase) // f gets ; komma und semikolon erkennen und alles in groß buchstaben (=uppercase) (strtok)
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
char delimiter[] = ", ; \n";
char string[MAX_WORD_LEN];
char stringcopy[MAX_WORD_LEN];
char *stringptr;
file = fopen("words.txt", "r"); file = fopen("words.txt", "r");
if (file == NULL) if (file == NULL)
{ {
printf("Fehler: Datei konnte nicht geöffnet werden!\n"); printf("Fehler: Datei konnte nicht geöffnet werden!\n");
return 1; return 1;
} }
else (file != NULL) else
{ {
printf("Datei konnte geöffnet werden"); printf("Datei konnte geöffnet werden");
fgets(string, MAX_WORD_LEN, file);
strcpy(stringcopy, string);
stringptr = strtok(stringcopy, delimiter);
while (stringptr != NULL){
stringptr = strtok(NULL, delimiter);
maxWordCount ++;
}
} }
} }
}
/*
char words[MAX_LINE_LEN][MAX_WORD_LEN];
unsigned int wordCount =0;*/