Inputting Non ASCII characters to scanf(“%s”)

后端 未结 2 950
花落未央
花落未央 2021-01-12 14:59

Is there a way one can issue non ascii hex characters to a scanf that uses %s ? I\'m trying to insert hexadecimal chars like \\x08\\xDE\\xAD and so

2条回答
  •  天命终不由人
    2021-01-12 15:28

    I assume you want to feed arbitrary data on stdin (since you read with scanf).

    You can use the shell to create the data and pipe it into your program, e.g.

    printf '\x08\xDE\xAD' | yourprogram
    

    Note that this will only work as long as there are no white-space characters to be fed (because scanf with a %s format stops at white-space).

提交回复
热议问题