程序如下: #include <stdio.h> #include <string.h> #include <conio.h> int findStr(char *str,char *substr) { int n=0; char *p,*r; while(*p) { p=str;
r=substr;
while(*r)
if(*r==*P){r++;p++;}
else break; if(*r=='\0') n++; str++; } return n; } main() { char str[81], substr[3]; int n; clrscr() printf("请输入原字符串:"); gets(str); printf("请输入子字符串:"); gets(substr); puts(str); puts(substr); n=findStr(str,substr); printf("n=%d\n",n); }
问题是:如果我输入的原字符串是asd asasdfg asd as zx67 as mklo 输入的子字符串是as 为什么我电脑上输出的结果是0?