Counting garlic -- String Length and String Length

Source: Internet
Author: User

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}

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.