.
This commit is contained in:
23
bac2/os/chap0/ex6.c
Normal file
23
bac2/os/chap0/ex6.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
unsigned int count_char_occurence(char string[], char target);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char test[] = "test test";
|
||||
printf("%s -> %d\n", test, count_char_occurence(test, 't'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int count_char_occurence(char string[], char target){
|
||||
int i = 0, ret = 0;
|
||||
while(string[i] != '\0'){
|
||||
if(string[i] == target){
|
||||
ret++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user