This works:
I'm getting a warning about 'assignment of incompatible pointer type' though.
Can't figure out what a pointer to the location of a char should be I guess.
Code:
int main()
{
char str1[]="Testing a string of text";
char str2[]="esting";
char *ptr1;
char *ptr2;
int idx;
ptr1 = &str1;
ptr2 = strstr(str1,str2);
idx = ptr2 - ptr1;
printf( "\nptr1:%d ptr2:%d Idx=%d\n", ptr1,ptr2,idx);
return 0;
}
This doesn't work. I can't figure out how to get the strings into the indexOf function:
Code:
#include <stdio.h>
#include <string.h>
int indexOf(char *str1, char *str2)
{
char *ptr1;
char *ptr2;
int idx;
ptr1 = &str1;
ptr2 = strstr(str1,str2);
idx = ptr2 - ptr1;
printf( "\nptr1:%d ptr2:%d Idx=%d\n", ptr1,ptr2,idx);
return idx;
}
int main()
{
char str1[]="Testing a string of text";
char str2[]="esting";
int idx;
idx = indexOf(str1,str2);
printf( "\nIdx=%d\n", idx);
return 0;
}