c++相关函数

#include<iostream>
using namespace std;
/*
strcpy字符串拷贝
strcat字符串连接
strcmp字符串比较
"adf">"aabb"  >为1,<为-1,=为0
strlen测试字符串的长度  不包括'\0'
atoi 数字字符串转换为数字
"1234"->1234
*/
int main(){
/*    //实现strcpy(b,a)
    char a[10] = "abcdef";
    char b[10];
    //cout << strcpy(b, a) << endl;
    int i = 0;
    while ((b[i] =a[i] )!= '\0')
    {
        i++;
    }
    cout << b << endl;
*/
    
/*    //实现strcat(a, b)
    char a[10] = "abcd";
    char b[10] = "efg";
    //cout << strcat(a, b) << endl;
    int i = 0;
    while (a[i] != '\0')
    {
        ++i;
    }
    for (int j = 0; (a[i + j] = b[j]) != '\0'; j++);
    cout << a << endl;
*/

/*    //实现strcmp(a, b)    
    char a[10] = "abcd";
    char b[10] = "abde";
    //cout << strcmp(a, b) << endl;
    int i = 0;
    while (a[i] != '\0'&&b[i] != '\0'&&a[i]==b[i])
    {
        ++i;
    }
    if(a[i]>b[i])
    cout << 1 << endl;
    else if(a[i]<b[i])
    cout << -1 << endl;
    else
    cout << 0 << endl;
*/    

/*    //实现strlen(a)    
    char a[10] = "abcdef";
    //cout << strlen(a) << endl;
    int i = 0,sum=0;
    while (i<10)
    {
        if (a[i] != '\0')
        {
            sum++;
        }
        i++;
    }
    cout << sum << endl;
*/

/*    //实现atoi 
    char a[20] = " -1234";
    int i = 0, s = 0;
    while (' ' == a[i] || '\t' == a[i] || '\n' == a[i])//判断是否为空格
    {
        ++i;
    }
    bool flag = false;
    if ('+' == a[i] || '-' == a[i])
    {
        if ('-' == a[i])
            flag = true;
        i++;
    }
    while (a[i] >= '0'&&a[i] <= '9')
    {
        s = s * 10 + a[i] - '0';
        ++i;
    }
    if (flag)
        s = -s;
    cout << s << endl;
    return 0;
*/
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值