2022-9-3 异常的思路,感觉智商不在线

1、从终端中输入一串字符,求出空格的个数;ab_cd_e_\n --->遇到\n表示输入结束
                       ---->数组中存储ab_cd_e ----->求出空格个数
              2、删除字符串中的空格,要求只用一个数组 “aa_b_cc” --->结果 “aabcc”

              3、完成strcmp和strcat函数,再独立完成strlen和strcpy函数

1.

#include<stdio.h>

int main(int argc, const char *argv[])
{
    char s[32]={0};
    printf("请任意输入一串字符串!\n");
    gets(s);
    int i=0;
    int count=0;
    while(s[i]!='\0'){
        if(s[i]==' '){
            count++;
        }
        i++;
    }
    printf("输入的空格的个数为%d\n",count);
    return 0;
}
 

2.

#include<stdio.h>

int main(int argc, const char *argv[])
{
    char s[64]={0};
    int i=0;
    int j=0;
    gets(s);
    puts(s);
    char *p1=s;
    char *p2=s;
    while(*p2!='\0'){
        if(*p2==' '){
            p2++;
        }else{
            *p1=*p2;
            p1++;
            p2++;
        }
    }
    *p1='\0';
    puts(s);
    return 0;
}
3.

#include<stdio.h>

int main(int argc, const char *argv[])
{
    char s1[32]="hello";
    char s2[32]="world";
    int i=0,j=0;
    int a=0;
    while(s1[i]!=s2[j]){
        i++;
        j++;
    }
    a=s1[i]-s2[j];
    printf("a=%d\n",a);

    return 0;
}
 

4.

#include<stdio.h>

int main(int argc, const char *argv[])
{
    int i=0,j=0;
    char s1[32]="hello";
    char s2[32]=" world!";
    puts(s1);
    puts(s2);
    while(s1[j]!='\0'){
        j++;
    }
    while(s2[i]!='\0'){
        s1[j]=s2[i];
        i++;
        j++;
    }
    s1[j]='\0';
    puts(s1);
    return 0;
}
 

5.

#include<stdio.h>

int main(int argc, const char *argv[])
{
    char s1[32]="hello";
    char s2[32]="world";
    puts(s1);
    puts(s2);
    int i=0,j=0;
    while(s2[i]!='\0'){
        s1[i]=s2[i];
        i++;
    }
    s1[i]='\0';
    puts(s1);
    return 0;
}
 

6.#include<stdio.h>
#include<string.h>
int main(int argc, const char *argv[])
{
    char s[32]="hello";
    int i=0;
    int len=0;
    while(s[i]!='\0'){
        i++;
    }
    printf("%d",i);
    putchar(10);
    len=strlen(s);
    printf("len=%d\n",len);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值