0

I write WINDOWS CLI APP using mingw. I need to read stream that contain mixed raw binary data (0x00) and chars (0x30 for exaple) from console. I try to use main.exe < test.bin (redirect file stream to stdin)

 ch=getchar();
or ch=getch();

But this functions does not read data correctly. Where is my mistake? This is file content: Raw data and decoded text File content

I try to trace app using gdb but app does not stop at ch=getchar(). I suppouse the problem is in terminal mode but i have no idea how to resolve it. If i send simple text file with hex values debug work fine.

Artem
  • 1
  • What's your raw data and what is the decoded data? If your data is binary you need to read the input in binary mode to avoid line break conversions. – Brecht Sanders Oct 30 '22 at 18:23
  • In the left part raw binary data 0x01 0x30 0x31 etc..What is the binary mode? This is special console terminal mode? How I can switch to it? I suppose when I use getch() instead of getchar() this function read key codes directly from keyboard not from stdin. – Artem Oct 31 '22 at 09:34
  • 1
    Some suggestions here: https://stackoverflow.com/questions/1598985/c-read-binary-stdin – Brecht Sanders Oct 31 '22 at 10:20

0 Answers0