Home Ask Login Register

Developers Planet

Your answer is one click away!

pee2pee January 2017

C: IF statement not firing when expected

I have the following function. The executable runs fine. At the prompt, after the program is run, I enter \x0037337331, the value of B is set as B: 0x31333337

Any advice on how I'd trigger to open log.txt

int play() {

    int a;
    int b;
    char buffer[010];
    a = 0x41414141;
    b = 0x42424242;

    if (write(STDOUT_FILENO, "For a moment, nothing happened. Then, after a second or so, nothing continued to happen.\n> ", 91) < 0) {

    if (read(STDIN_FILENO, &buffer, 0xC) < 0) {                                              

    if (a == 31337) {

    else if (b == 1337) {

    else {
        printf("B: 0x%08x\n", b);



Ed Heal January 2017

You have two mistakes:


char buffer[010]; // This is octal i.e. 8!

should be

char buffer[0xc]; 


read(STDIN_FILENO, &buffer, 0xC)

should be

read(STDIN_FILENO, buffer, 0xC)

As you need the pointer to the start of the buffer.


Also you need to add the null character to buffer before system.

Post Status

Asked in January 2017
Viewed 3,004 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life