Srinivasan Rajappa
Srinivasan Rajappa

Reputation: 59

Standard Input C: Incorrect string if $ is present

I am trying to take input from the STDIN. If the input string starts with character '$' then the input is not converted to string as it is.

int main(int argc, char*argv[]){
     printf("%s\n",argv[1]);
}

Can someone please let me know to why C compiler replaces the characters with '0' if it encounters the '$' symbol ?

Upvotes: 5

Views: 120

Answers (1)

Mike Andrews
Mike Andrews

Reputation: 3206

It's not your program. It's your shell interpreting it as a variable, then passing its value to your program.

To work around this, escape the $ when you invoke the program from your shell.

./yourprogram '$arg'

Upvotes: 10

Related Questions