有两个字符串picooc s1和s2区别,编写程序判断s1是否是s2的字串,是的话输出s1在s2的起始位置

编写一个求字串的函数sub_str(char *s1,char *s2,int m,int n),作用是将字符串s1中从第m个字符开始的n个字放入字符串s2中;该怎么处理
编写一个求字串的函数sub_str(char *s1,char *s2,int m,int n),作用是将字符串s1中从第m个字符开始的n个字放入字符串s2中;编写一个求字串的函数sub_str(char *s1,char *s2,int m,int n),作用是将字符串s1中从第m个字符开始的n个字放入字符串s2中;问题出在什么地方,求高手指出问题的地方#include&stdio.h&#include&string.h& &
void sub_str(char *s1,char *s2,int m,int n){ &
int l1,l2,i; & &
l2=strlen(s2); &
for(i=m;i&=n;i++) &
(s2+l2-1)++=(s1+m-1)++;} &
printf(&%s&,s2);} &
int main(){ &
int m=0,n=0; &
char* s1; &
char* s2; &
char a[80],b[80]; &
printf(&输入字符串1&); &
gets(s1); &
printf(&输入字符串2&);&
gets(s2); &
printf(&输入m和n的值&); &
scanf(&%d %d&,&m,&n); &
sub_str(s1,s2,m,n);}
实现得文艺一点应该像下面  C/C++ code  void sub_str(char *s1,char *s2,int m,int n){
memcpy(s2,s1+m,sizeof(char)*n);
huanhuan123& &
(0) (0)
下标从0算还是1算,根据自己的需要选择就可以了
huanhuan3& &
(0) (0)
仅供参考,虽然不是C语言。(字符串下标从1开始数)  C/C++ code  func strmid(len,str1,str2,pos)
var string1:127;
string1=ljust(str1,& &,len);
if (pos eq 1)
string1=str2
&substr(string1, pos+length(str2));
string1=substr(string1, 1, pos-1)
&substr(string1, pos+length(str2));
string1=substr(string1,1,len);
return string1;
huanhuan3& &
(0) (0)
代码我就不贴了, 没意思, LZ,貌似是你在赋值那个循环后没有加个'\0' , 也就是s2[i] = '\0' ,亲 , 不信你可以试一下.
huanhuan0832& &
(0) (0)
提示:本问题已关闭,不能解答。
:: 最近更新<meta name="description" content="编程问题——字符串比较在C语言中,有一个strcmp函数,其功能是比较两个字符串s1和s2。如果s1
s2,则返回一个正数。请编写一个你">
编程问题——字符串比较在C语言中,有一个strcmp函数,其功能是比较两个字符串s1和s2。如果s1
s2,则返回一个正数。请编写一个你_百度作业帮
编程问题——字符串比较在C语言中,有一个strcmp函数,其功能是比较两个字符串s1和s2。如果s1
s2,则返回一个正数。请编写一个你
编程问题——字符串比较在C语言中,有一个strcmp函数,其功能是比较两个字符串s1和s2。如果s1
s2,则返回一个正数。请编写一个你自己的字符串比较函数my_strcmp,来实现strcmp函数的功能。已知用户输入的字符串不会超过20个字符,但其中可能包含有空格。  输入有两行,每一行是一个字符串(内部没有空格)。  输出一个整数,若s1>s2,输出1;若s1<s2,输出-1;若s1=s2,输出0。样例LifeLove-1C语言的
要用函数知识
int my_strcmp(char *s1,char *s2){
for(i=0;j=0;*(s1+i)I='\0'&&*(s2+j)!='\0';i++,j++) {
if(*(s1+i)>(s2+j))
if(*(s1+i)>(s2+j))
return -1;}
if(*(str+i)=='\0'&&*(str+j)=='\0')
return 0; else
if(*(str+i)=='\0')
return -1;else reurn 1;}字符定位:&编写程序返回字符串s2的任一字符在字符串串s1的位置
一. 程序功能
编写程序返回字符串s2的任一字符在字符串串s1的位置, 如果s2的所有字符都不在s2中, 打印提示信息.
二. 程序源码
#include &stdio.h&
#define MAXSTRING 1000
#define NO 0
#define YES 1
int ch_location(char s1[], char ch);
int any_location(char s1[], char s2[]);
int any(char s1[], char s2[]);
int main(void)
& & char ch,
s1[MAXSTRING];
s2[MAXSTRING];
& & int i,
& & while(1)
& printf("Please input the first string
dealt(ctrl+c to quit): "); & &
& gets(s1);
& printf("Please input the second string(included
strings found): ");
& gets(s2);
& if (any(s1, s2) == -1)
printf("All chacters in string:%s are not found in string:%s\n\n",
s2, s1); &
& & return 0;
//location of single chacter in a string
int ch_location(char s1[], char ch)
& & int i, i_
& & i = 0;
& & i_loc = -1;
& & while (s1[i] != '\0')
& &//"\0" means the end of
& if (ch == s1[i]) &
& //judge if ch is equal to s1[i]
& & & i_loc =
& & & //save the
& & //quit, if there is no break,
the rightest location will be returned
& i++; & &
& & &//incr i to
think of next character of s1
& & return i_
& &//return the location
//use ch_location to find the location of string in a
int any_location(char s1[], char s2[])
& & int i, j, i_
& & j = 0;
& & while (s2[j] != '\0')
& //"\0" means the end of s2
& ch = s2[j]; &
& & & //assign
the value of s2[j] to ch
& i_loc = ch_location(s1, ch); &
&//call ch_location
& if (i_loc != -1) &
& & & //judge by
the value of i_loc
printf("Char:%c of String:%s is found in String:%s and location is
%d\n", ch, s2, s1, i_loc);
& & if (i_loc != -1)
& printf("\n");
& & return i_
//location of any chacter of string in a
int any(char s1[], char s2[])
& & int i, j, i_
& & j = 0;
& & while (s2[j] != '\0')
&//"\0" means the end of s2
& i = 0; & &
& & &//i = 0 to
get the beginning of s1 &for each chacter of
& i_loc = -1; &
& & //assign -1 to i_loc
& ch = s2[j]; &
& & //assign the value of s2[j]
& while (s1[i] != '\0') &
& & & //"\0"
means the end of s1
& & & if (ch ==
s1[i]) & & &
& &//judge if equal
& & i_loc = &
& &//save location
& & & i++;
& &//incr i to think of next
chacter of s1
& if (i_loc != -1)
printf("Char:%c of String:%s is found in String:%s and location is
%d\n", ch, s2, s1, i_loc);
& & if (i_loc != -1)
& printf("\n");
& & return i_
三. 程序小结
1. 将字符串分解后处理(这里可以借助char_location实现对字符串中所有字符定位)
2. 函数any(s1,s2)整合字符定位和调用字符定位的字符串定位函数
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。您要找的资源已被删除、已更名或暂时不可用。有两字符串s1,s2,编写程序寻找他们的最大公共字符串,返回最大公共字符串的字符个数。
[问题点数:50分,结帖人Snailer]
有两字符串s1,s2,编写程序寻找他们的最大公共字符串,返回最大公共字符串的字符个数。
[问题点数:50分,结帖人Snailer]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2005年1月 C/C++大版内专家分月排行榜第二
本帖子已过去太久远了,不再提供回复功能。

我要回帖

更多关于 picooc s1和s2区别 的文章

 

随机推荐