I just wrote a program in c language which uses command line arguments and i tried to print the first argument. when i execute program with following command
./a.out $23
and try to print the first argument using the below code
printf("%s", argv[1]);
the output is just
3
Am i missing something here, that command line arguments are treated differently if some special characters are present. can some one explain this behavior.
You need to escape the $ character.
Try this:
./a.out \$23
Presumably the $2 is being treated as a shell variable. Try escaping the dollar sign:
./a.out \$23
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With