Library functions to implement C-string manipulation

Source: Internet
Author: User

#include <stdio.h>//string Length (version one)//using a character array to implement int mystrlen1 (char s[]) {int len = 0;while (S[len]! = ')} {len++;} return Len;} String length (version two)//with character pointer implementation int Mystrlen2 (char *s) {int len = 0;while (*s! = ')} {len++;s++;} return Len;} int main () {char str[] = "Hello"; int n = mystrlen1 (str);p rintf ("%d\n", n), int m = mystrlen2 (str);p rintf ("%d\n", m); return 0;}
#include <stdio.h >//string copy (version one)//using an array to implement void Mystrcpy1 (char S[],char t[]) {int i=0;while ((s[i]=t[i])! = ' + ')//assignment First, Compares whether the string terminator {i++;}} Copy of string (version two)//use pointer to implement void Mystrcpy2 (char *s,char *t) {while ((*s = *t)! = ' + ') {s++;t++;}} Copy of string (version three)//using pointers for void mystrcpy (char *s, char *t) {while (*s++ = *t++);   C Non-0 means logic is true, so do not compare with ' \ '} int main () {char a[] = "Hello", char b[100],c[100];mystrcpy1 (b,a);p rintf ("%s\n", b); Mystrcpy2 (c,a);p rintf ("%s\n", c); return 0;}



Library functions that implement C-string manipulation

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.