字符串
//使用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);
}