, then the in...">

C standard input: invalid string if $ is present

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

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

Can someone please tell me why the C compiler replaces the characters "0" if it encounters the character "$"?

+5
source share
1 answer

This is not your program. It is your shell that interprets it as a variable, and then passes its value to your program.

To get around this, exit $ when you call the program from your shell.

 ./yourprogram '$arg' 
+10
source

All Articles