简体   繁体   中英

Printing another program in c

In the original code I have a line:

input = scanf("%c%c%c%c%c", &input_key[0], &input_key[1], &input_key[2], &input_key[3], &input_key[4]);

since I have to print the program out I did:

printf("   input = scanf(\"%c%c%c%c%c\", &input_key[0], &input_key[1], &input_key[2], &input_key[3], &input_key[4]);\n");

however the output came out to:

input = scanf("dd≡Ç", &input_key[0], &input_key[1], &input_key[2], &input_key[3], &input_key[4]);

How to fix this?

% is a special character in printf that is replaced by an input argument. If you want to print the % literal, you should escape it through %% .

So your code should be:

printf("   input = scanf(\"%%c%%c%%c%%c%%c\", &input_key[0], &input_key[1], &input_key[2], &input_key[3], &input_key[4]);\n");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM