[{"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 在VS里面会报错
解决方法就是报错给的提示:‘scanf’:该函数或变量可能不安全。考虑改用scanf_s。
所以,在使用VS时,需要改为scanf_s
(2)gets函数(输入字符串的函数)在VS里面无法使用
下面的代码在VS里面无法运行,在VC6.0可以正常运行
判断是否有新单词出现,出现则加一。如果上一个字母是空,则判断为新单词,个数加一; 如果上一个字母不为空,则认为上一个单词未结束,个数不变; #include
<stdio.h> int main() { char a[100]; int i, in_word, word_num; gets(a); word_num
= 0; // 初始化单词个数为0 in_word = 0; // 标记位,标记是否在单词内 for (i = 0; a[i]; i++) { if (a[i]
== ' ') { // 检测到空格 in_word = 0; // 设置标记位为不在单词内 } else if (in_word == 0) { //
在单词内 word_num++; // 统计单词个数 in_word = 1; // 设置标记位为在单词内 } } printf("单词个数为%d\n",
word_num); }
可以换成如下代码实现单词个数的统计
#include <stdio.h> int main() { printf("输入一行字符:\n"); char ch; int i, count = 0,
word= 0; while ((ch = getchar()) != '\n') if (ch == ' ') word = 0; else if (
word== 0) { word = 1; count++; } printf("总共有 %d 个单词\n", count); return 0; }
(3)使用字符串处理函数
puts gets函数无法在VS里面使用,可以用putchar getchar
【连接strcat函数
复制strcpy strncpy 函数
比较strcmp 函数
测长度strlen函数
转换大小写atrlwr strupr函数】
以上,部分可用,部分需要加_s 才能使用。
vc++6.0
比较三组字符串的大小:
#include<stdio.h> #include<string.h> int main() { char str[3][20]; char string[
20]; int i; for (i = 0; i < 3; i++) gets(str[i]); if (strcmp(str[0], str[1]) > 0
) strcpy(string, str[0]); else strcpy(string, str[1]); if (strcmp(str[2], string
) > 0) strcpy(string, str[2]); printf("\n最大的字符串为:\n%s\n", string); return 0; }
结果:
dfacwsd
dwqafda
dfasefd
最大的字符串为:
dwqafda
Press any key to continue