字符串处理函数

//

//  main.c

//  字符串处理函数

//

//  Created by qingyun on 14-5-13.

//  Copyright (c)  All rights reserved.

//


#include <stdio.h>

#include <string.h>


// strlen

void test() {

        // 测量字符串常量的字符长度(不包括\0这个字符)

    int len = strlen("刘军亮");

    //printf("%d\n", len);

    

    // 测量字符串变量的字符长度

    char s[] = "lml";

    //printf("%d\n", strlen(s));

    

    char s1[] = {'m', 'j'};

    

    //结果是5 内存中的存储是:mjlmj

    printf("%d\n", strlen(s1));

    

}


// strcpy

void test1() {

    char left[10];

    

    //拷贝"itcast"到数组left

    strcpy(left, "itcast\n");

    

    printf("%s", left);

}


//strcat

void test2() {

    char left[10] = {'m', 'j', '\0', 'i', 't', 'c', 'a', '\0'};

    // left的第一个\0开始拼接ios这个字符串

    //拼接的结果是: mjios\0

    strcat(left, "ios");

    // 拼接的结果:mjios\0a\0

    

    printf("%s", left);

}


// strcmp

void test3() {

    

    int delta = strcmp("abc", "aac");

    printf("%d\n", delta);

}

int main(int argc, const char * argv[])

{

    test3();

    return 0;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值