I understand that hexadecimal numbers can be put in a string using \x . For example, 0x41 0x42 can be placed in a string as "\x41\x42" .
char * ptr = "\x41\x42" ; printf( "%s\n" , ptr )
\x discarded, and 41 is considered by the compiler as hex.
But if I pass it into my program via command line arguments, this will not work.
// test.c main( int argc , char * argv[] ) { printf( "%s\n" , argv[1] ) ; }
$ gcc -o prog test.c
$. / prog "\ x41 \ x42"
\ X41 \ x42
$ .prog \ x41 \ x42
\ X41 \ x42
What I expected was AB as in example 1.
Why is this so? Why does this presentation method not work with command line arguments?
How can the value in argv[1] , which we know for sure, be a hexadecimal string, can be converted to a hexadecimal number (without parsing, as is done in the first example)?
Thank you for your time.
source share