generated from freudenreichan/info2Praktikum-Wortsalat
input.c fertig 1
This commit is contained in:
parent
8800ac8b5c
commit
e7d3cc9023
@ -8,21 +8,11 @@
|
|||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
/*file = fopen("words.txt", "r"); //liest das doc ein
|
|
||||||
if (file == NULL)
|
|
||||||
return -1;*/
|
|
||||||
FILE *ptr;
|
|
||||||
char text [2000];
|
char text [2000];
|
||||||
char line[200];
|
char line[200];
|
||||||
char value;
|
|
||||||
int i = 0;
|
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)) {
|
while (fgets(line, sizeof(line), ptr)) {
|
||||||
for (int j = 0; line[j] != '\0'&& i < sizeof(text)-1;j++) {
|
for (int j = 0; line[j] != '\0'&& i < sizeof(text)-1;j++) {
|
||||||
@ -32,9 +22,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|||||||
}
|
}
|
||||||
text[i] = '\0';
|
text[i] = '\0';
|
||||||
|
|
||||||
fclose(ptr);
|
|
||||||
|
|
||||||
printf("%s\n", text);
|
|
||||||
|
|
||||||
//sortierung der wörter in words(unterhalb)
|
//sortierung der wörter in words(unterhalb)
|
||||||
|
|
||||||
@ -52,9 +40,10 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|||||||
|
|
||||||
zaehler++;
|
zaehler++;
|
||||||
}
|
}
|
||||||
|
maxWordCount=zaehler;
|
||||||
|
|
||||||
|
|
||||||
//alle buchstaben in großbuchstaben ändern
|
//alle Buchstaben in Großbuchstaben ändern
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -66,6 +55,6 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user