zoukankan      html  css  js  c++  java
  • <string.h>的学习

    感觉学习代码库最好的方法就是运行一下。

    下面附上结果和示例代码 

    #include <stdio.h>
    #include <string.h>
    
    int main(){
        const char * cs="Hello World";
        const char * ct="Hello";
        char * s=malloc(20);
        memset(s,0,20);
        char * t;
        int c='o';
        const size_t n=3;
        //strcpy(s,ct);
        printf("const char * cs=Hello World;
    
        const char * ct=Hello;
    
        int c=o;
    
        const size_t n=3;
    
        ");
        printf("=============================================
    ");
        printf("	the result of strcpy(s,ct) is: %s
    ",strcpy(s,ct));
        t=strncpy(s,ct,n);
        *(t+n)='';
        printf("	the result of char * strncpy(s,ct,n) is: %s
    ",t);
        memcpy(s,ct,strlen(ct));//copy ct to s
        printf("	the result of char * strcat(s,ct) is: %s
    ",strcat(s,ct));
        printf("	the result of char * strchr(cs,c) is: %s
    ",strchr(cs,c));
        printf("	the result of char * strrchr(cs,c) is: %s
    ",strrchr(cs,c));
        printf("	the result of size_t strspn(cs,ct) is: %d
    ",strspn(cs,ct));
        printf("	the result of char * strpbrk(cs,ct) is: %s
    ",strpbrk(cs,ct));
        printf("	the result of size_t strlen(cs) is: %d
    ",strlen(cs));
    }

     结果如下:

    image

  • 相关阅读:
    spring事务调用失效问题
    redis的主从、哨兵配置
    Lucene介绍与入门使用
    超详细“零”基础kafka入门篇
    消息队列——RabbitMQ学习笔记
    linux中RabbitMQ安装教程
    JAVA正则
    JAVA String类
    JAVA lang包介绍
    JAVA枚举
  • 原文地址:https://www.cnblogs.com/kissazi2/p/3140514.html
Copyright © 2011-2022 走看看