Creating an empty .zip file in C++

The stated problem, that no file is created, is impossible to answer with the information given. It is most likely due to an invalid file path. However, the OP states in a comment that the path in his example is not the real code.


EDIT: the hex string example that I cited originally was wrong, I just tested.

This code works:

#include <stdio.h>

auto main() -> int
{
    FILE* f = fopen("foo.zip", "wb");
    //fwrite( "\x80\x75\x05\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 22, 1, f );
    fwrite( "\x50\x4B\x05\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 22, 1, f );
    fclose(f);
}

Harumph, one cannot even trust Stack Overflow comments. Not to mention accepted answers.


Original text:

Assuming that the OP now has edited the code so that the part below is the real code, then this constant

{80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

is not identical to

"\x80\x75\x05\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

Can the OP spot the relevant difference?

Further, given that, can the OP infer anything about his source of information?

My example from a comment elsewhere.

Leave a Comment