Reputation: 58
I have a problem: I am trying to do basic operations on string (compare, copy, print to console) passed to a program as an argument. This string contains char '$' ex. "$1$23$45". The problem is that I can't display it properly, the console just shows some random chars - in this case "35" is printed to the screen.
So, I start the program
./Lab8Dec $1$23$45
which does the following
printf("%s", argv[1]);
This text is suposed to be printed:
$1$23$45
But instead this is the result:
35
Is there any way to treat '$' in variable as a normal character, not as a special one?
Upvotes: 0
Views: 68
Reputation: 311843
$
isn't a special character in C. It is, however, a character indicating a variable in most linux shells. You can protect your input form the shell by using single quotes:
./Lab8Dec '$1$23$45'
Upvotes: 2