This commit is contained in:
ketrptr committed 2024-11-25 14:22:45 +01:00
commit 3738c83af8
19 files changed
+333

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
CLFAGS=-g -ggdb -Wall
all: strAnalyzer.c
gcc $(CLFAGS) strAnalyzer.c -o strAnalyzer
BIN
View File
Binary file not shown.
+38
View File
@@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
int stringLen(char **s, int *eCount) {
int count = 0;
int idx = 0;
*eCount = 0;
while (*(*s + idx) != '\0') { //(*(*s+idx)) == (*s)[idx]
if ((*s)[idx] == 'e') {
*eCount += 1;
}
count++;
idx++;
}
// newline (\n) am ende soll nicht gezaehlt werden deshalb count -1 falls
// count >0 ansonten 0 um zun verhindern dass negative stringLen
// zurueckgegeben weird falls count = 0
return count > 0 ? count - 1 : 0;
}
int main() {
char *str = NULL;
size_t size; // max allocated size of str (allocated by getdelim)
int numberEs;
int ret = getline(&str, &size, stdin);
if (ret == -1) { // getline failed. free allocated mem and return
free(str);
return 1;
}
printf("read: %s", str);
int len = stringLen(&str, &numberEs);
printf("it is %d chars long. It contains the letter \'e\' %d times\n", len,
numberEs);
free(str);
return 0;
}