How Do You Find The Index Of A Character In A String C ?
How Do You Find The Index Of A Character In A String C ? Just subtract the string address from what strchr returns: char *string = “qwerty”; char *e; int index; e = strchr(string, ‘e’); index = (int)(e – string); Note that the result is zero based, so in above example it will be 2.