函数mycmp(char *s,char *t)的功能是比较字符串s和t的大小,当s等于t时返回0,当s>t时返回正值,当s<t时返回负值,请填空。mycmp( char *s,char *t){ while (*s==*t) { if (*s==’\0’)return 0; ++s;++t; } return();}
第1题:
以下函数的功能是将两个字符串s和t连接起来,横线部分应该填写什么语句? void conj(char *s,char *t) { char *p=s; while(*s) _______; while(*t) {*s= *t;s++;t++ } *s='0'; }
A.*s
B.s
C.s++
D.s--
第2题:
以下函数的功能是将两个字符串s和t连接起来,横线部分应该填写什么语句? void conj(char *s,char *t) { char *p=s; while(*s) ; while(*t) {*s= *t;s++;t++ } *s='0'; }
A.*s
B.s
C.s++
D.s--
第3题:
(选做题)查找字符串。输入两个字符串s和t,在字符串 s中查找子串t,输出起始位置,若不存在则输出-1。要求自定义函数char *search(char *s,char *t)返回子串t的首地址,若未找到,则返回NULL。
第4题:
函数strcmp( )的功能是对两个字符串进行比较,当s所指字符串和t所指字符串相等时,返回值为0;
当s所指字符串大于t所指字符串时,返回值大于0;当s所指字符串小于t所指字符串时,返回值小于
0(功能等同于库函数strcmp( ) ),请填空。
include <stdio.h>
int strcmp ( chat * s, char * t)
{ while( * s && * t && * s=【 】
{ s++;t++; }
return 【 】;
}
第5题:
下列给定程序中,函数fun()的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为abcdabfab,t所指字符串的内容为ab,则函数返回整数3。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
int fun (char *s, char *t)
{int n; char *p, *r;
n=0;
while(*s)
{p=s;
r=t;
while (*r)
/**************found**************/
if(*r==*p) {r++; p++}
else break;
/*************found**************/
if(r=='\0')
n++;
s++;
}
return n;
}
main()
{char s[100], t[100]; int m;
clrscr();
printf("\nPlease enter string s: ");
scanf ("%s",s);
printf("\nPlease enter substring t: ");
scanf ("%s",t);
m=fun (s,t);
printf("\nThe result is: m=%d\n", m);
}
第6题:
请编写一个函数int compare(char *s,char *t)), 该函数的功能是对两个字符串进行比较。当s所指字符串和t所指字符串相等时,返回值为0;当s所指字符串大于是t指字符串时,返回值大于0;当s所指字符串小于t所指字符串时,返回值小于0。
注意:部分源程序已存在文件PROC8.cpp中。
文件PROC8.cpp的内容如下:
//PROC8.cpp
include <iostream>
include <string>
using namespace std;
int compare(char *s,char *t)
{
//* * * * * * * * *
}
int main ()
{
char str1[100],str2[100];
int result;
cout<<"Input the first string\n";
cin>>str1;
cout<<"Input the second string\n";
cin>>str2;
result=compare(str1,str2);
if (result==0)
cout<<"string1=string2 ! \n";
else if (result>0)
cout<<"string1>string2 ! \n";
else
cout<<"string1<string2 ! \n";
return 0;
}
第7题:
函数sstrcmp()的功能是对两个字符串进行比较。当s所指字符串和t所指字符串相等时,返回值为0;当s所指字符串大于t所指字符串时,返回值大于0;当s所指字符串小于t所指字符串时,返回值小于0(功能等同于库函数strcmp()),请填空。#include<stdio.h>int sstrcmp(char *s,char *t){ while(*s&&*t&&*s= =){s++;t++; }return;}
第8题:
函数my_cmp()的功能是比较字符串s和t的大小,当s等于t时返回0,否则返回s和t的第一个不同字符的ASCII码差值,即s > t时返回正值,当s < t时返回负值。请填空。
my_cmp(char *s, char *t)
{while (*s == *t)
{if (*s == ′\0′)return 0;
++s; ++t;
} return 【18】 ;
}
第9题:
A.strcmp1(char *s, chat *t)
{ for ( ;*s++==*t++ ;)
if (*s=='\0') return 0
return (*s-*t)
}
B.strcmp2(char *s, char *t)
{ for( ;*s++==*t++ ;)
if (!*s) return0
return (*s-*t)
C.strcmp3(char *s, char *t)
{ for ( ;*t==*s ;)
{ if (!*t) return 0
t++
s++}
return (*s-*t)
}
D.strcmp4(char *s, char *t)
{ for( ;*s==*t;s++,t++)
if (!*s) return 0
return (*t-*s)
}