M
mike3
Hi.
I did this in a C program, which involves searching for the occurence
of a string
in another string:
---
posptr = strstr(MyString, StringToFind);
if(posptr == NULL) return(-1); /* Didn't find it */
return(((int)(StringToFind - &MyString[0]))/sizeof(char)); /* turn
returned pointer into a zero-indexed character offset */
---
("MyString" and "StringToFind" are both arrays of type char and null-
terminated.)
It's that last part I'm wondering about. Is that part "legal" in
standard C? Safe?
If not, what's a more "legal" or "safe" method to accomplish what I'm
trying
to accomplish with this?
I did this in a C program, which involves searching for the occurence
of a string
in another string:
---
posptr = strstr(MyString, StringToFind);
if(posptr == NULL) return(-1); /* Didn't find it */
return(((int)(StringToFind - &MyString[0]))/sizeof(char)); /* turn
returned pointer into a zero-indexed character offset */
---
("MyString" and "StringToFind" are both arrays of type char and null-
terminated.)
It's that last part I'm wondering about. Is that part "legal" in
standard C? Safe?
If not, what's a more "legal" or "safe" method to accomplish what I'm
trying
to accomplish with this?