mirror of
https://github.com/theoleuthardt/learningC.git
synced 2026-06-13 09:37:53 +00:00
Initial commit
This commit is contained in:
commit
826d4c8c9d
81 changed files with 7268 additions and 0 deletions
30
uebung8/aufgabe4.c
Normal file
30
uebung8/aufgabe4.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int wordCount(const char *string){
|
||||
int count = 0;
|
||||
bool inWord = false;
|
||||
size_t strSize = strlen(string);
|
||||
printf("Länge des Strings: ");
|
||||
printf("%zu\n", strSize);
|
||||
|
||||
for (; *string != '\0'; string++) {
|
||||
if(*string == ' ' || *string == ',' || *string == '.'){
|
||||
inWord = false;
|
||||
} else {
|
||||
if(!inWord){
|
||||
count++;
|
||||
inWord = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *string = "Coders are also just human with addictions and needs.";
|
||||
printf("String: %s\n", string);
|
||||
printf("Anzahl der Wörter im String: %d", wordCount(string));
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue