基础代码|字符串操作
admin
2023-08-16 11:18:54
0次

1.反转字符串:

define NUM 80 #include int main(){ char cc[NUM],c='a'; int i=0,ncount=0; printf("please input a line char:\n"); gets(cc); printf("\n\nyou input:%s\n",cc); for(i=0; cc[i]!='\0'; i++){ ncount++; } printf("the length of %s is %d\n",cc,ncount); for(i=0; i

2.输入字符串的多种方式:
#define NUM 80 #include int main(){ char cc[NUM],bb[NUM],c; int i=0,ncount=0; printf("please input a line char: \n"); scanf("%s",cc); printf("\n\nyou input :%s\n",cc); for(i=0; cc[i]!='\0'; i++){ if(cc[i]>='A'&&cc[i]<'A'+25){ cc[i]=cc[i]+32; } } printf("after to lower Case:%s\n",cc); //方法一遇到空格就结束输入 //方法二 printf("\nplease input another string:\n "); gets(bb); printf("\nanother:\n%s\n",bb); for(i=0; bb[i]!='\0'; i++){ if(bb[i]>='A'&&bb[i]<'A'+25){ bb[i]=bb[i]+32; } } printf("\nafter to lower case:\n%s\n",bb); }

基础代码|字符串操作
文章图片




方法三
#define NUM 80 #include #include int main(){ char cc[NUM],c; int i=0,ncount=0; while(ncount='a'&&cc[i]<97+25){ cc[i]=cc[i]-32; } } printf("after tocUpper Case:%s\n",cc); }

基础代码|字符串操作
文章图片

3.在字符串中查询某个字符:
#define NUM 80 #include int main(){ char cc[NUM],c='a'; int i=0,nCount=0,nPos[NUM]; printf("please input a line char:\n"); gets(cc); printf("please input a char:\n"); c=getchar(); printf("you input:%s\n",cc); printf("you will find :%c\n",c); while(i



4.找到并删除字符
#define NUM 80 #include int main(){ char cc[NUM],c='a'; int i=0,j=0; printf("please input a line char:\n"); gets(cc); printf("please input a char:"); c=getchar(); printf("\nyou input:%s\n",cc); printf("you will find :%c\n",c); while(i

基础代码|字符串操作
文章图片

#define NUM 80 #include int main(){ char cc[NUM],c='a'; int i=0,j=0,nCount=0,nPos[NUM]; printf("please input a line char:\n"); gets(cc); printf("please input a char:"); c=getchar(); printf("\nyou input :%s\n",cc); printf("you will find :%c\n",c); while(i

基础代码|字符串操作
文章图片

5.找到字符串出现的位置
(1)找到一个字符串首次出现的位置
#define NUM 256 #include int main(){ char cc[NUM],findC[NUM]; int i=0,nPos=0,j=0,lensub=0; printf("please input a line char:\n"); gets(cc); printf("please input a find string:"); gets(findC); printf("\nyou input:%s\n",cc); printf("you will find :%s \n",findC); for(i=0; (findC[i]!='\0'&& i0){ break; } i++; } if(nPos>0){ printf("the position:%d\n",nPos); } else{ printf("not found!"); } }


基础代码|字符串操作
文章图片

【基础代码|字符串操作】(2)找到一个字符串各次出现的位置
#define NUM 256 #include int main(){ char cc[NUM],findC[NUM]; int i=0,nPostmp=0,j=0,lensub=0,nCount=0,nPos[NUM]; printf("please input a line char:\n"); gets(cc); printf("please input a find string:"); gets(findC); printf("\nyou input :%s\n",cc); printf("you will find :%s\n",findC); for(i=0; (findC[i]!='\0'&&i

基础代码|字符串操作
文章图片

6.删除一个子串各次出现
(1)使用复制到新数组的方法:
#define NUM 256 #include int main(){ char cc[NUM],findC[NUM],newcc[NUM]; int i=0,nPos[NUM],nCount=0,j=0,lensub=0,nPostmp=0,k=0; printf("please input a line char:\n"); gets(cc); printf("please input a find string:"); gets(findC); printf("\nyou input\n"); printf("%s\n",cc); printf("you will find:%s \n",findC); for(i=0; (findC[i]!='\0'&& i

基础代码|字符串操作
文章图片

(2)直接在原数组中移动以删除子串:
#include #define NUM 256 int main(){ char cc[NUM],newcc[NUM],findC[NUM]; int i=0,nPos[NUM],nCount=0,j=0,lensub=0,nPostmp=0,k=0; printf("please input a line char:\n"); gets(cc); printf("please input a find string:"); gets(findC); printf("you will find:%s\n",findC); for(i=0; i

基础代码|字符串操作
文章图片




7.在字符串的指定位置插入字符串
#define NUM 256 #include int main(){ char cc[NUM],findC[NUM]; int i=0,j=0,insertIndex=0,ncc=0,nfindc=0; printf("please input the line char:"); gets(cc); printf("please input the insert string:"); gets(findC); printf("%s\n",cc); scanf("%d",&insertIndex); for(i=0; (findC[i]!='\0'); i++); nfindc=i; for(i=0; (cc[i]!='\0'); i++) ncc=i; ncc++; for(i=ncc; i>=insertIndex; i--){ cc[i+nfindc]=cc[i]; } for(i=0; i

基础代码|字符串操作
文章图片

8.获取字符串的一部分
#define NUM 256 #include int main(){ char cc[NUM],findC[NUM]; int i=0,j=0,iStart=0,iEnd=0; printf("please input a line char:\n"); gets(cc); printf("%s\n",cc); printf("please input start position,end position:"); scanf("%d %d",&iStart,&iEnd); for(i=iStart; (i

基础代码|字符串操作
文章图片

9.将两个字符串连接起来
#define NUM 256 #include int main(){ char cc[NUM],cc2[NUM]; int i=0,j=0,lencc=0,lencc2=0; printf("please input a first string:\n"); gets(cc); printf("please input a secondary string:\n"); gets(cc2); for(i=0; cc[i]!='\0'; i++){ lencc=i; } lencc++; for(i=0; cc2[i]!='\0'; i++){ lencc2=i; } lencc2++; for(i=0; i

基础代码|字符串操作
文章图片

10.两个字符串进行比较


上一篇:jQuery插件

下一篇:雅集

相关内容

热门资讯

大浪淘金APP黑幕揭秘:内盘操...   大浪淘金APP平台最隐蔽的黑幕,在于其完全封闭的内盘交易系统。这个看似与国际市场接轨的交易平台,...
告别固定工资实现财富自由?一品...   普通投资者被广告宣传诱导,注册就送现金,充值返现金券等等这些宣传方式,都是在引流到平台开户,不怕...
哈易购APP打着现货交易幌子搞...   网络上各类白银、铂金等贵金属投资广告铺天盖地,不少平台以"现货交易"为名,暗中却从事着非法期货交...
5元起投!高额收益?中国白银、...   上海华通白银国际交易中心有限公司(以下简称“华通白银国际”)打着“白银、铂金现货订购”的旗号,实...
"九州订购APP、起...   近年来,贵金属投资热度持续攀升,但乱象也随之而来。一些不法分子趁机搭建虚假交易平台,打着"低门槛...
坚锅淘金APP投资者频繁爆仓亏...   坚锅淘金APP对外宣称是贵金属现货交易平台,日常出入金看似畅通无阻,给人一种合规运营的假象。但事...
斗金订购APP“5元订购现货”...   斗金订购APP“5元订购现货”骗局揭秘:充值易、回本难,越陷越深!  许多投资人在未核实平台合规...
贵金属APP乱象曝光:&quo...   当前市场上部分贵金属类APP未取得正规交易资质,涉嫌误导消费者参与白银、铂金等商品的非合规交易!...
华通白银、银宝街APP被指虚假...   警惕现货白银投资陷阱:上海华通白银背后的平台涉嫌非法期货交易  近年来,各类现货白银交易平台以“...
充值送300,月入过万?别被量...   如今,网络上充斥着大量未经批准的贵金属及其他产品订购交易平台。这些平台普遍缺乏合法经营资质,却将...
鑫汇智投APP贵金属非法期货、...   鑫汇智投APP贵金属非法期货、人为控盘,大量投资者遭恶意收割  鑫汇智投APP长期以“低门槛、高...
矅光智策APP非法贵金属交易骗...   不少投资人在矅光智策APP上进行贵金属交易后出现了严重亏损。许多人在下载该平台时,根本不清楚其是...
飞鸽订购APP非法期货交易骗局...   飞鸽订购APP非法期货交易骗局,很多投资者根本没搞懂规则就盲目充值,买涨买跌跟买cai票一样!平...
天龙白银APP被操控的非法期货...   中小投资者在网络平台参与商品现货订购交易,表面看似合规合法,实则暗藏诸多难以察觉的风险。商品现货...
下载送试玩金?千万别碰!带你揭...   当前,许多贵金属APP交易平台正采用欺诈性营销手段。它们通过抖音等短视频平台,以“5元起投”“充...
泡泡淘金APP骗局:打着&qu...   泡泡淘金APP骗局:打着"商品订购"幌子,实则非法期货收割投资者!投资需谨慎,切勿轻信“高额回报...
南商云购APP虚假电子盘背后的...   南商云购是虚假电子盘吗?它是否具备合规的交易资质?这个曾经的"现货电子盘"如今摇身一变,披上了"...
警惕"祥龙订购&qu...   祥龙订购APP、掌上银牛APP等平台背后的运营方——四川禄宏商品现货市场有限公司,仅具备现货交易...
中国白银、华银:虚假宣传、后台...   中国白银APP宣称是上市公司“中国白银集团”与“上海华通白银国际交易中心”旗下的现货交易平台,提...
起底“优品订购”APP非法期货...   “优品订购”APP根本不具备任何合法的交易资质。其背后的运营方仅凭随便注册一家公司、开发一款交易...