compile-fan
compile-fan

Reputation: 17615

How to output arbitrary stuff to stdout?

#include <stdio.h>

int main()
{
        int i = 0;
        char stuffing[44];
        for(i = 0; i <= 40; i+=4)
        {
                *(int *)&stuffing[i] = 0x4004f8;
        }
        puts(stuffing);
}

The above terminates as soon as it gets to 0x00, how to output all stuff in stuffing?

Upvotes: 0

Views: 89

Answers (1)

mu is too short
mu is too short

Reputation: 434585

You want to use fwrite for outputting arbitrary binary data:

fwrite(stuffing, 1, sizeof(stuffing), stdout);

The puts function writes a C string and C strings are terminated by '\0' (AKA 0x00).

UPDATE: In comments elsewhere you say that you want "ASCII characters to be read by gets". First of all, don't ever use gets, never, don't even mention its name. Secondly, if you just want ASCII characters then why go to all the trouble of stuffing the raw bytes into a char buffer when you could just do this:

printf("%d\n%d\n%d\n%d\n", 0x4004f8, 0x4004f8, 0x4004f8, 0x4004f8);

or something similarly straight forward?

Upvotes: 2

Related Questions