I wrote a script to hide user input during runtime it works as a simple script but i want to integrate into c program but gives following errors:

warning: missing whitespace after macro name error: expected ')' before 'Password' 

can someone tell me what i'm doing wrong.

Here's the c program:

#include"header.h" #define SHELLSCRIPT"\ #bin/bash\n\ printf"Password Please:"\n\ stty -echo\n\ read pass\n\ stty echo\n\ printf'\n'\n\ sleep"2"\n\ echo "$pass"\n\ " int main() { puts("Will execute sh with following script:"); puts("SHELLSCRIPT"); puts("Starting now"); system(SHELLSCRIPT); return 0; } 
3

1 Answer

Here is a fixed version of your code:

// Compile with: // gcc c-shellscript.c -o c-shellscript #include <stdio.h> #include <stdlib.h> #define SHELLSCRIPT "\ printf 'Password Please:';\n\ stty -echo;\n\ read pass;\n\ stty echo;\n\ printf '\\n';\n\ sleep 2;\n\ echo $pass;" int main() { puts("Will execute sh with following script:"); puts("---------"); puts(SHELLSCRIPT); puts("---------"); puts("Starting now"); system(SHELLSCRIPT); return 0; } 

However, I don't think it is good practice to do things this way. It is also much much easier to create a separate shellscript file and just call that instead, even if you generate the shellscript file from within your code.

Have a look at these for more info:

1