C language programming exercise reference answer chapter 7 (2) pointer and array main function parameters

Source: Internet
Author: User

/* 7.16 implement the strlen () function for testing the string length ()*/
# Include "stdio. H"
Int strlen (char * P );
Void main ()
{
Char S1 [20] = "s1s2s3s4 ";
Char * P = S1;
Printf ("S1 length: % d \ n", strlen (S1 ));
Printf ("S1 length: % d \ n", strlen (p ));
Printf ("length of the string ABC123: % d \ n", strlen ("ABC123 "));
}

Int strlen (char * P)
{
Int length = 0;
While (* P! = '\ 0 ')
{
Length ++;
P ++;
}
Return length;
}
/* 7.19 The pointer array is used as the main function parameter. Note: According to the exercise requirements, this file must be named welcome. C */
# Include "stdio. H"
Void main (INT argc, char * argv [])
{
Int I;
Printf ("Welcome to you ");
For (I = 1; I <argc; I ++)
Printf ("% s", argv [I]);
}

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.