input in char einlesen und mit sotierung in char words begonnen

This commit is contained in:
Ben Skuppin 2025-11-02 15:31:01 +01:00
parent f5337d419f
commit 83b8ac3e87

View File

@ -8,7 +8,49 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
file = fopen("words.txt", "r"); //liest das doc ein
/*file = fopen("words.txt", "r"); //liest das doc ein
if (file == NULL)
return -1;
return -1;*/
FILE *ptr;
char text [2000];
char line[200];
char value;
int i = 0;
int start = 0, end= 0;
ptr = fopen("words.txt", "r");
if (ptr == NULL) {
printf("Datei konnte nicht geöffnet werden.\n");
return 1;
}
while (fgets(line, sizeof(line), ptr)) {
for (int j = 0; line[j] != '\0'&& i < sizeof(text)-1;j++) {
text[i++] = line[j];
}
}
text[i] = '\0';
fclose(ptr);
printf("%s\n", text);
for (int k = 0 ; k == sizeof(text) || value == '\0' ; k++ ) {
text[k]=value;
if ((value == '\n') || (value ==' ') || ( value == ',')|| ( value == ';'))
{
end = k-1;
}
}
fclose(ptr);
}