Preventing Windows program from interpreting ^Z as end of file

eleijonmarck

My job is to translate a application from C -> C++ that have been installed on a linux distribution.so I wish the functionallity of C and linux.

I have a problem with reading binary file. It says that it reaches the EOF when it encounters a ctrl-Z character before it has reached the actual end of the file.

Precious execution in bash

zcat file.txt.gz | txtToBinary | binaryToOutput

Execution in command prompt

txtToBinary.exe < file.txt | binaryToOutput.exe

Raw text file

 R  5643BYIDK           DK0016060346 11DKKXKLY 160               1
 R 10669VJK 98 1        IS0000004018  4ISKXICE 240         5000000
 M814

txtToBinary.exe - Sample Output:

^@^@^@ hello ^@    ^Z^@^@^@^@
^@^@^[SWMA ^Y^YC

The problem is that the program interprets the first ^Z as the end of file.

Tried so far

My solutions has been to do the following when compiling on windows using c++

Execution in command prompt

txtToBinary.exe < file.txt | binaryToOutput.exe
int main(int argc, char* argv []){
    int loop (args_t* args){

    for (;;){
        char data [1024];
        int temp = read_msg (data, sizeof (data));
}

int read_msg(void* data, int size){
    _setmode(_fileno(stdin), _O_BINARY);
    _setmode(0,_0_BINARY);
    if(fread(((unsigned char *)data)+sizeof(*hdr),hdr->size-sizeof (*hdr),1,stdin) != 1);
        if(feof(stdin))
             printf("End of file error\n");
}

I have also tried Cygwin which some of the answers have me. But that also failed.

StackOverflow Answers

When looking at answer here in SO, we see Windows, Windows EOF, Binary solution,Binary Mode and Stream data end at byte 26 and Reaching EOF early Windows. They tell me that:

- Windows keys (CTRL + Z, ^Z) makes an end of file

- I have to read in binary format

eleijonmarck

I found the answer to my question. It had to do with where you read from. You need to put

_setmode(0,_0_BINARY);

in the main() function!!!!!!!! Remember this, otherwise other reads or writes will not be included.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Preventing Windows program from interpreting ^Z as end of file

From Dev

Preventing R from interpreting text as numeric

From Dev

Preventing Input past end of file error

From Dev

Interpreting JPEG Chroma Subsampling read from file

From Dev

Add/Remove bytes from end of file on Windows

From Dev

Add/Remove bytes from end of file on Windows

From Dev

C:How to load a list from a file and save it at the end of the program

From Dev

Preventing windows resizing from enlarging PictureBoxes

From Dev

Preventing a MEX file from crashing in MATLAB

From Dev

Preventing a file from attempting to be attached twice

From Dev

a ctl file preventing machine from starting up

From Dev

selinux is preventing from execute access on the file centos

From Dev

Preventing Eclipse from opening external program inside Eclipse editor

From Dev

Preventing duplicate entry from being added (C program)

From Dev

Program opening up in the top edge of the screen, preventing it from being dragged

From Dev

AT SELECTION-SCREEN ON <FIELD> is preventing the program from retrieving data

From Dev

Interpreting access flags from hex value in java class file

From Dev

Reading and correctly understanding/interpreting control characters from a file (python)

From Dev

Loading Data from File to Data Structure in C++ and Interpreting It

From Dev

Prevent pandas from interpreting 'NA' as NaN in a string : csv file

From Dev

Windows smart Screen (windows 8.1) messages preventing from running the application

From Dev

Windows startup - how to run a program as administrator from a batch file

From Dev

How to handle the File hand-off from windows in a python program

From Dev

Start a program with a file from the recently used list in Windows 8

From Dev

How to prevent a Windows program from modifying attributes of a folder/file?

From Dev

Ignoring file extension when running program from Windows context menu?

From Dev

How to prevent windows defender antivirus from deleting a file of a program

From Dev

Threads preventing program termination

From Dev

Reading and interpreting a logical expression in a program

Related Related

  1. 1

    Preventing Windows program from interpreting ^Z as end of file

  2. 2

    Preventing R from interpreting text as numeric

  3. 3

    Preventing Input past end of file error

  4. 4

    Interpreting JPEG Chroma Subsampling read from file

  5. 5

    Add/Remove bytes from end of file on Windows

  6. 6

    Add/Remove bytes from end of file on Windows

  7. 7

    C:How to load a list from a file and save it at the end of the program

  8. 8

    Preventing windows resizing from enlarging PictureBoxes

  9. 9

    Preventing a MEX file from crashing in MATLAB

  10. 10

    Preventing a file from attempting to be attached twice

  11. 11

    a ctl file preventing machine from starting up

  12. 12

    selinux is preventing from execute access on the file centos

  13. 13

    Preventing Eclipse from opening external program inside Eclipse editor

  14. 14

    Preventing duplicate entry from being added (C program)

  15. 15

    Program opening up in the top edge of the screen, preventing it from being dragged

  16. 16

    AT SELECTION-SCREEN ON <FIELD> is preventing the program from retrieving data

  17. 17

    Interpreting access flags from hex value in java class file

  18. 18

    Reading and correctly understanding/interpreting control characters from a file (python)

  19. 19

    Loading Data from File to Data Structure in C++ and Interpreting It

  20. 20

    Prevent pandas from interpreting 'NA' as NaN in a string : csv file

  21. 21

    Windows smart Screen (windows 8.1) messages preventing from running the application

  22. 22

    Windows startup - how to run a program as administrator from a batch file

  23. 23

    How to handle the File hand-off from windows in a python program

  24. 24

    Start a program with a file from the recently used list in Windows 8

  25. 25

    How to prevent a Windows program from modifying attributes of a folder/file?

  26. 26

    Ignoring file extension when running program from Windows context menu?

  27. 27

    How to prevent windows defender antivirus from deleting a file of a program

  28. 28

    Threads preventing program termination

  29. 29

    Reading and interpreting a logical expression in a program

HotTag

Archive