Php function source code C write [continuous update], php source code

Source: Internet
Author: User

Php function source code C write [continuous update], php source code

Strlen ()

Returns the string if the string length is obtained.stringLength; ifstringIf it is null, 0 is returned.

# Include <stdio. h> # include <stdlib. h> # define N 1000int count = 0; int strlen (char * str) {int num = 0; // define a counter while ('\ 0 '! = * Str ++) {num ++;} return num;} void test (char * str) {printf ("the string to be tested is % s \ n ", str); count = strlen (str); // call the printf function ("the input string length is % d \ n", count);} void main () {char str1 [] = "hello world! "; // This assignment method will automatically end with a '\ 0' char * str2 =" hello world! "; // This assignment method will automatically end with a '\ 0' char str3 [20] =" world hello! "; // This assignment method will automatically add '\ 0' char str4 [N] = {0}; test (str1); test (str2 ); test (str3); printf ("Enter the array to be tested: \ n"); gets (str4 ); // This function adds the NULL character '\ 0' test (str4) at the end );
System ("pause ");}

 

Strcpy ()

Head. h

#include<stdio.h>#include<string.h>#define N 100void strcpy1(char *str_cpy, char const *str);

_ Strcpy (). c

 

# Include "head. h "void strcpy1 (char * str_cpy, char const * str) // to ensure read-only of the primary array, add" const "to modify {while (* str! = '\ 0') {* str_cpy = * str; str_cpy ++; str ++;} * str_cpy =' \ 0'; // Add the terminator}

 

Main. c

 

# Include "head. h "void main () {char str [N]; char str_cpy [N]; printf (" Enter the main string array: \ n "); scanf ("% s", & str); strcpy1 (str_cpy, str); // copy printf ("% s \ n", str ); printf ("% s \ n", str_cpy); getchar ();}

 

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.