Counting garlic -- String Length and String Length
Time Limit: 1000 ms memory limit: 65536 KB
On the right side, we provide a basically completed program, read a string, call a function called str_len to calculate the length of the string, and output it.
You should have discovered that the str_len function is not complete. Complete the str_len function without modifying the function prototype to implement the above functions.
Sample Input
Abcdefg
Sample output
7
1 # include <stdio. h>
2 # include <stdlib. h>
3 int str_len (char * str);
4 int main () {
5 char * str = (char *) malloc (100 * sizeof (char ));
6 scanf ("% s", str);
7 printf ("% d", str_len (str);
8 free (str);
9 return 0;
10}
11 int str_len (char * str) {
12 // complete your function
13 int count = 0, I = 0 here;
14 while (* (str + I )! = '\ 0')
15 {
16 count ++;
17 I ++;
18}
19 return count;
20}