init
This commit is contained in:
commit
3738c83af8
19 files changed
+333
No files matched your search
@@ -0,0 +1,4 @@
|
||||
CLFAGS=-g -ggdb -Wall
|
||||
|
||||
all: strAnalyzer.c
|
||||
gcc $(CLFAGS) strAnalyzer.c -o strAnalyzer
|
||||
Executable
BIN
Binary file not shown.
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user