c++编程
编写一个程序,求字符串s1中s2的位置,若s1包含s2返回s2在s1中第一次出现的位置,否则返回-1。
#include<stdio.h> #include<string.h> int main() { char c[100]; char c1[50]; int n; printf("请输入母字符串:"); gets(c); printf("请输入要检索的字符串:"); gets(c1); n=strstr(c,c1)-c+1; if(strstr(c,c1)==NULL) printf("字符串%s在字符串%s中没有出现。\n",c1,c); else printf("字符串%s在字符串%s的第%d个位置出现。\n",c1,c,n); return 0; }