70,020
社区成员




#include<stdio.h>
#define SIZE 80
int main(void)
{
char s1[SIZE],ch;
int i,a;
printf("请输入一串字符串:");
gets(s1);
printf("输入待查找的字符:");
scanf("%c",&ch);
for(i=0;s1[i]!=ch&&i<SIZE;i++);
i=i+1;
if(i>SIZE)
i=0;
if(i>0)
printf("待查字符出现在字符串中的%d位置处\n",i);
else
printf("字符串中没有待查找的字符\n");
return 0;
}
int num(char *p, char *p2, int *n)
{
char *temp; //临时指针用来做判断
int k = strlen(p);//算出字符串Str的长度;也就是strinp的长度;
while (p2 != '\0') //如果到了那个比较长的字符串的末尾跳出循环
{
temp =strstr(p2, p);
if(temp!= NULL) //判断字符串STROUT。里面是否存在str 没有存放的话就等于null下面就直接跳出循环
{
(*n)++; //调入进来的n++;
p2 = p2 + strlen(p);
continue;
}
else
{
break;
}
}
}
int main()
{
char strinp[] = "crazyspopcorn"; //定义一个字符型数组变量
char strout[] = "crazyspopcornzuishuaiqilecrazyspopcornzuipiaole";
int n = 0;
num(strinp, strout, &n);
printf("%d",n);
system("pause");
}
头文件的话。楼主自家加哦~~这是调用函数的。楼主可以自己改写成一个函数的。希望能帮助到你;谢谢里面都有注释的。