c 语言中字符串的使用

字符串
//使用char数组(str1)定义一个字符串hello world
//打印输出str字符串中的最后一个字符
//打印输出str字符串
//打印输出str字符串中的world
//打印输出str字符串的首地址和尾(\0)地址
//打印出字符串的大小
//将每个单词的首字母大写,并打印输出
//将str字符串倒序打印输出
//找到o的位置下标并打印
//使用char数组(str2)定义一个字符串hello world i love you
//将str2 拆分为两个字符串hello world 和 i love you 并用定义的指针p_str2_1 和
//p_str2_2 进行指向,最后通过指针打印输出字符串。

答案:

#include <stdio.h>
#include <string.h>

int main() {
        char str1[] = "hello world";
        printf("%s\n",&str1[10]);
        printf("%s\n",str1);
        printf("%s\n",(str1+6));
        printf("%p %p\n",&str1[0],&str1[11]);
        printf("%ld\n",strlen(str1));
        str1[0]='H';
        str1[6]='W';
        printf("%s\n",str1);
        for(int i=strlen(str1);i>0;i--) {
                printf("%c",*(str1+i-1));
        }
         printf("\n");



        char str2[]="hello world i love you";
        for(int i=0;i<strlen(str1);i++){
                if(str1[i]== 'o')
                {
                        printf("%d\n",i);
                }
        }
        char *p_str2_1=&str2[12];
        char *p_str2_2=&str2[0];
        str2[11]='\0';
        printf("%s\n %s \n",p_str2_1,p_str2_2);
}
         
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值