Merge remote-tracking branch 'origin/main'
This commit is contained in:
parent
1c5c7f639c
commit
bbada12891
38
wortlen.c
Normal file
38
wortlen.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#define MAX_WORDLENGTH 100
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int frequency[MAX_WORDLENGTH] = {0};
|
||||||
|
char text[1000];
|
||||||
|
int wordlength = 0;
|
||||||
|
|
||||||
|
printf("Bitte geben Sie einen Text ein:\n");
|
||||||
|
fgets(text, sizeof(text), stdin);
|
||||||
|
|
||||||
|
for (int i = 0; text[i] != '\0'; i++) { // schleife liest
|
||||||
|
if (isalnum(text[i])) { //isalnum ueberprueft ob das es ein wort oder zahl ist also kein leerzeichen, satzzeichen
|
||||||
|
wordlength++; // zaehlt die buchstaben in dem wort
|
||||||
|
} else {
|
||||||
|
if (wordlength > 0) { // wenn das groeßer wird das als wordlength zb 3 buchstaben
|
||||||
|
frequency[wordlength]++; // dann wird der counter fuer 3 hochgezaelt
|
||||||
|
wordlength = 0; // um das naechste wort zu zaehlen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (wordlength > 0) {
|
||||||
|
frequency[wordlength]++; // das ist fuer das letzt wort damit es gezaehlt wird
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Haeufigkeitsverteilung der Wortlaengen:\n");
|
||||||
|
for (int i = 1; i < MAX_WORDLENGTH; i++) { // geht von 1-100 und schaut welche wortlaengen vorhanden sind
|
||||||
|
if (frequency[i] > 0) {
|
||||||
|
printf("Wortlaenge %d: %d\n", i, frequency[i]); // printet die anzahl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user