简体   繁体   中英

Input non-printable ascii characters into scanf

So I've seen these two questions:

And unfortunately these did not provide me for an answer I've needed let's say I'm dependent within some output of a certain program and can't tell for sure which values I need to enter ahead of program's execution, I'd rather enter some input for example for this code:

#include <stdio.h>

int main()
{
    char a[10] = {0};
    printf("\n----------- %x\n", (unsigned int) a); 
    scanf("%s", a);
    for(int i = 0; i < 10;  i++)
        printf("%d\n", (int) a[i]);
}

as an example, I'm waiting after the printf within the following program has reached, then

input -> some input containing non-printable ascii characters

program output-> 04 08 01 05 02 10 09 12 02 02 (All these are values of non-printable ascii characters)

and again I'm looking for a way to enter them directly

  • I'm not looking for a way to do this by implementing some functionality within my code, my code is given as an example of a program
  • When saying during runtime, I mean after the program has started running - hence the prints within my program have reached
  • I apologize if this was unclaer

On Linux you can type Control-v before a control character to enter it literally. So to type the character with code 0x04 , type Control-v Control-d .

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