answersLogoWhite

0

The standard C library includes two simple utilities to find the first or last occurance of a given character within a given string, strchr() to search from the start and strrchr() for the reverse start from the end.

Subject to the chosen search direction, you could use one of these two simple API. Both return a pointer to the location of the matching character within the string, or NULL if no such character is found.

Note that this approach assumes a mutable string, a string stored in writeable memory. A string literal is a constant string and not generally mutable (even though some compilers are very casual about this). That is, strchr("the quick brown fox", 'q') will return a pointer to the first 'q', but since the string is a string of constant characters, you shouldn't use the pointer to change the letter found.

To search and modify, you'd use string of variable characters, such as one allocated with the malloc() or strdup() standard API, or one created as a char array.

User Avatar

Wiki User

11y ago

What else can I help you with?