I have trying C and so far it's gone great but this has been driving me mad today.

I could swear scanf worked earlier but its crashing my programs?
I know you get this problem when you forget the pointer thing &

but this should work

#include<stdio.h>

int main()
{
    int userinput;

    scanf("%d",&userinput);
    printf("%d",userinput);
    getchar();

    return 0;
}

Im using Vc++Express with .c on my source code.

I have trying C and so far it's gone great but this has been driving me mad today.

I could swear scanf worked earlier but its crashing my programs?
I know you get this problem when you forget the pointer thing &

but this should work

#include<stdio.h>

int main()
{
    int userinput;

    scanf("%d",&userinput);
    printf("%d",userinput);
    getchar();

    return 0;
}

Im using Vc++Express with .c on my source code.

What kind of error are you getting?

I think you need to describe exactly what you are seeing because I believe your analysis of what's happening is not correct. I suspect your program is not crashing.

What kind of error are you getting?

I think you need to describe exactly what you are seeing because I believe your analysis of what's happening is not correct. I suspect your program is not crashing.

The program runs untill input is entered with scanf this program just closes after you hit enter.

I tried with MinGW with MSYS and it worked fine so its a VC++ problem

UPDATE:
After more playing around it seems the windows console is to blame?
It runs fine on the MSYS bash console for windows but the reg exits on input

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.