[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
基础知识:
1.scanf的读取规则有"默认读取到空格结束"
解决方法:scanf("%[^\n]",arr); 作用:“读取到换行结束”
2.对字符串常用gets,puts
gets()读取字符串包括空格
put(x)相当于printf("%s\n", x) 比正常printf会多一个换行
3.字符数组和字符串的区别(有无\0)
例1:char s1[3]={'a','b','c'},s2[4]={'a','b','c','0'};
s1,s2都为字符数组,但是s2同时也是字符串。
4.初始化规则:
char str[1000]=''abdce'' --------默认后面加\0(即字符串)
5.两种打印字符数组的方式(1.遍历%c 2.直接打印%s)
例:
#include<stdio.h> int main() { char arr1[4], arr2[5]; scanf("%s",
arr1);//&arr1[] //方式1(一个一个出来) int i = 0; for (i = 0; i < 4; i++) { printf("%c",
arr1[i]); } printf("\n"); //方式2(一整个出来) printf("%s", arr1); }
输出结果:
———————————————————————————————————————————
题目:将一个字符串str的内容倒过来
#include<stdio.h> #include<string.h> int main() { char arr1[10000] = { 0 };
scanf("%[^\n]", arr1); int len = strlen(arr1); int left = 0; int right = len -
1; while (left < right) { char tmp = arr1[left]; arr1[left] = arr1[right];
arr1[right] = tmp; left++; right--; } printf("%s\n", arr1); return 0; }