[最新]c措辞 字符串复制、连接、比拟函数完成[最新]c措辞 字符串复制、连接、比拟函数完成
1.字符串比较函数:
#include
int strcmp(char *s, char *t) {
int i;
for(i=0;s[i]==t[i];i++)
if(s[i]=='\0')
return 0;
return s[i] - t[i]; }
int strcmp1(char *s, char *t) {
for(;*s==*t; s++, t++)
if (*s == '\0')
return 0;
return *s-*t;
}
int...
[最新]c措辞 字符串复制、连接、比拟
数完成
1.字符串比较函数:
#include
int strcmp(char *s, char *t) {
int i;
for(i=0;s[i]==t[i];i++)
if(s[i]=='\0')
return 0;
return s[i] - t[i]; }
int strcmp1(char *s, char *t) {
for(;*s==*t; s++, t++)
if (*s == '\0')
return 0;
return *s-*t;
}
int main()
{
char s[]="aaabb";
char t[]="aaabd";
printf("%d\n", strcmp1(s,t)); }
2. 字符串复制函数
#include
void strcpy(char *s, char *t) {
while(*s++=*t++)
;
}
int main()
{
char s[10];
char t[]="abcde";
strcpy(s,t);
printf("%s\n",s); }
3.字符串连接函数
#include
void mystrcat(char *s, char *t) {
while(*s!='\0')
s++;
while((*(s++)=*(t++))!='\0')
;
}
int main()
{
char s[10]="abcd";
char t[]="efg";
mystrcat(s,t);
printf("%s\n",s);
本文档为【[最新]c措辞 字符串复制、连接、比拟函数完成】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。