func mystr_idx code
This commit is contained in:
20
mystr_idx.c
Normal file
20
mystr_idx.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
int mystr_idx(char *str, char *substr);
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
printf("Print you string\n");
|
||||||
|
char s[100]; scanf("%s", s);
|
||||||
|
printf("Print substring\n");
|
||||||
|
char ss[100]; scanf("%s", ss);
|
||||||
|
printf("Your substr has intex:%d\n", mystr_idx(s, ss));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int mystr_idx(char *str, char *substr)
|
||||||
|
{
|
||||||
|
int indx = strstr(str, substr) - str;
|
||||||
|
if(strstr(str, substr) == NULL)
|
||||||
|
{indx = -1;}
|
||||||
|
|
||||||
|
return indx;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user