IF you are using a multibyte charset (UTF-8, for example) you should convert this string to wchar_t string and use wcsrchr() instead of strchr():
Code:
/* test.c */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <locale.h>
int main( int argc, char *argv[] )
{
int n;
mbstate_t ps;
wchar_t *dest, *p;
size_t size;
if ( argc != 2 )
{
fputs( "Usage: test <string>\n", stderr );
return EXIT_FAILURE;
}
// You MUST setup LC_CTYPE for mbsrtowcs() to work!
setlocale( LC_CTYPE, "en_US.utf8" );
// allocate space to wchar_t string.
size = strlen( argv[1] );
if ( ! ( dest = malloc( sizeof( wchar_t ) * (size + 1) ) ) )
{
fputs( "Cannot allocate space for widechar string.\n", stderr );
return EXIT_FAILURE;
}
// Convert multibyte character string to wchar string.
memset( &ps, 0, sizeof ps );
mbsrtowcs( dest, (const char **)&argv[1], size, &ps );
// Try to find 'º' (notice the L in the literal).
if ( p = wcschr( dest, L'º' ) )
printf( "%p\n", p ); // print the pointer if found.
else
puts( "Not found" );
free( dest );
return EXIT_SUCCESS;
}
IF you are using ISO-8859-1 or WINDOWS-1252 encoding (single byte charset), strchr() will work just fine.