2

for some reason, when I try to compile my code the .exe file just disappears after its done... without any errors or warnings.

This is what my code looks like:

#include <stdio.h>
#include <stdlib.h>

typedef struct student_ 
{
    int matnum;
    char vorname[20];
    struct student_ *next;
} student;

int main (int argc, char **argv) 
{
    student hans;
    hans.matnum = 12;

    student peter;
    peter.matnum = 13;
    peter.next = NULL; // THIS PART CAUSES MY PROBLEM

    hans.next = &peter;

    student *curr = &hans;
    while(curr != NULL)
    {
        printf("matnum: %d\n", (*curr).matnum);
        curr = curr->next;
    }

    return 0; 
}

What I want it to do is iterate through curr and set it to the next everytime curr wasn't NULL already. So if next is NULL, than the while-loop should stop.

peter.next = NULL; // THIS PART CAUSES MY PROBLEM

This is how I want to achieve that but it doesn't work. :\


From the comments:

I don't get an error. AFter I type in "gcc -Wall -o test test.c" the test.exe is there for a second and then it gets deleted.

5
  • This doesn't make any sense; either it compiles, or it doesn't and you get error messages. Commented May 11, 2014 at 9:26
  • 1
    Is it compilation error, or run time error? Can you please copy the error text and paste in your question? Commented May 11, 2014 at 9:27
  • I don't get an error. AFter I type in "gcc -Wall -o test test.c" the test.exe is there for a second and then it gets deleted. Commented May 11, 2014 at 9:29
  • 1
    Does it remain when you delete the suspect line of code? Commented May 11, 2014 at 9:30
  • Yes. But then the program crashes, which makes sense because the pointer curr is set to something that is not a student. Commented May 11, 2014 at 9:33

1 Answer 1

6

The most plausible explanation for this is that your anti-virus software is deleting the executable. Your program compiles and runs fine here.

For whatever reason, the suspect line results in compiled code that your anti-virus software matches against a known virus. When you remove that line, it no longer matches the virus, but of course the program fails.

Temporarily disable your anti-virus to confirm this hypothesis.

Sign up to request clarification or add additional context in comments.

2 Comments

Holy cow I turned avast off and it works now! Thank you a lot!
@David +1 it was out of the box

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.