Source functions of string processing functions strcat, strcpy, strlen, and strcmp

Source: Internet
Author: User

  • /** Copyright and version statement of the program: * Copyright (c) 2012, Emy of computer science, Yantai University * All rights reserved. * file name: four functions are used to concatenate two character arrays, copy two character arrays, evaluate the length of strings in the character array, and compare the content of the two arrays. cpp * OPERATOR: Mao Tong * Completion Date: July 15, January 14, 2013 * version number: v1.0 * description of the task and solution section: pointer parameters * input Description: none * Problem description: * program output: "" * Problem Analysis: omitted * Algorithm Design: 4 functions written by myself */[cpp]/* concatenate two character arrays, copy two character arrays, evaluate the character string length in the array, and compare the two arrays. Similar to the functions of string processing functions strcat, strcpy, strlen, and strcmp. (Two methods are required, one is to use an array as the form parameter, and the other is to use a pointer as the form parameter.) the pointer is used as the real parameter */# include <iostream> using namespace std; int main () {void mystrcpy (char *, char *); void mystrcat (char *, char *); int mystrlen (char *); void mystrcmp (char *, char *); char str1 [100] = "I love china", str2 [100] = "I hate japan", str3 [100]; // Add the content of str2 to the char * p1, * p2, * p3; mystrcmp (str1, str2) behind str1 ); cout <endl <"mystrcmp function successful" <endl; cout <"str1 has" <mystrlen (str1) <"Characters" <endl; cout <"mystrlen function successful" <endl; mystrcpy (str1, str3); p1 = str1; p3 = str3; cout <"str1" <p1 <endl; cout <"str3" <p3 <endl; cout <"mystrcpy function successful" <endl; mystrcat (str1, str2); p1 = str1; p2 = str2; cout <"str1 =" <p1 <endl; cout <"str2 =" <p2 <endl; cout <"mystrcat function successful" <endl; return 0;} void mystrcat (char * p1, char * p2) {for (; * p1! = '\ 0'; p1 ++); for (; * p2! = '\ 0'; p2 ++) {* p1 = * p2; p1 ++;} * p1 =' \ 0';} int mystrlen (char * p1) {int I = 0; for (; * p1! = '\ 0'; I ++) ++ p1; return I;} void mystrcmp (char * p1, char * p2) {int I; while (! (I = * p1-* p2) & * p1 & * p2) p1 ++, p2 ++; if (I <0) cout <"str1 string small"; else if (I> 0) cout <"str2 string large";} void mystrcpy (char * p1, char * p3) {for (; * p1! = '\ 0'; p3 ++, p1 ++) {* p3 = * p1;} * p3 =' \ 0';}/* running result :*/

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.