
3个回答
展开全部
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int search(char * strSource, char * strFind)
{
int find_len=strlen(strFind);
int i=0;
int flag=0;
while( *(strSource+i) != '\0' ){
if(*(strSource+i) == *strFind){
if(strncmp(strSource+i,strFind,find_len) ==0){
flag++;
}
}
i++;
}
if(flag!=0){
printf("----找到了[%d]次---\n",flag);
}else{
printf("----没有找到---\n");
}
return 0;
}
int main()
{
char strSource[100] ="three boys have swum across three rivers for three times in three days.";
char strFind[10] = "three";
search(strSource,strFind);
return 0;
}
#include <string.h>
#include <malloc.h>
int search(char * strSource, char * strFind)
{
int find_len=strlen(strFind);
int i=0;
int flag=0;
while( *(strSource+i) != '\0' ){
if(*(strSource+i) == *strFind){
if(strncmp(strSource+i,strFind,find_len) ==0){
flag++;
}
}
i++;
}
if(flag!=0){
printf("----找到了[%d]次---\n",flag);
}else{
printf("----没有找到---\n");
}
return 0;
}
int main()
{
char strSource[100] ="three boys have swum across three rivers for three times in three days.";
char strFind[10] = "three";
search(strSource,strFind);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <string.h>
void find_str(char *str1,char *str2)
{
int i,j,k;
k = strlen(str2);
for(i = 0 ;*(str1 + i) != '\0';i ++)
{
if ( *(str1 + i) == *str2)
{
for(j = 0;j < k;j ++)
{
if(*(str1 + i +j ) != *(str2 + j))
break;
}
if (j == k)
printf("str2 first display at%d\n",i);
else
printf ("no find str2");
}
}
}
void main()
{
char s1[100],s2[10];
printf("input string s1:\n");
gets(s1);
printf("input the finding string s2:\n");
gets(s2);
find_str(s1,s2);
}
#include <string.h>
void find_str(char *str1,char *str2)
{
int i,j,k;
k = strlen(str2);
for(i = 0 ;*(str1 + i) != '\0';i ++)
{
if ( *(str1 + i) == *str2)
{
for(j = 0;j < k;j ++)
{
if(*(str1 + i +j ) != *(str2 + j))
break;
}
if (j == k)
printf("str2 first display at%d\n",i);
else
printf ("no find str2");
}
}
}
void main()
{
char s1[100],s2[10];
printf("input string s1:\n");
gets(s1);
printf("input the finding string s2:\n");
gets(s2);
find_str(s1,s2);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
调用函数strrch(),直接搞定,可以参考CSDN文档
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询