Code Block 'crash' on Enter Key

Pages: 12
I have recently started learning c Programming and I am working my way through a tutorial book.

When I am running code in Code Blocks I am experiencing what seems to be a crash.

I have tested a few routines and they all cause the crash so I'm pretty sure it's not the code.

The code I am running requires an entry and upon Enter being pressed I experience the 'crash'.

I receive a message saying - [I]file.exe has stopped working[I/]

I than have the option of clicking on Debug or Close Program.

If I click on Debug I am presented with a dialog headed - Visual Studio Just-in-time Debugger

I am struggling to fix this issue and I am guessing I have clicked something somewhere to cause this.

Any help or pointers would be hugely appreciated!

Thanks
If they're tutorials, then the code is probably short. Post it.
I'm not convinced it's the code as I went back to some tutorials that did work and they now no longer work, i.e I get the crash notification.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>

int main()
{
    int code;

    printf("Entyer the error code (1-3): ");
    scanf("%d",code);

    switch(code)
    {
        case 1:
            puts("Drive Fault, not your fault.");
            break;
        case 2:
            puts("Illegal format, call a lawyer.");
            break;
        case 3:
            puts("Bad filename, spank it.");
            break;
        default:
            puts("That's not a 1, 2 or 3");
    }
    return 0;
}
Well listing to your compiler might help, you should be getting at least a couple of warnings.

1
2
3
8:20: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'int' [-Wformat=]
8:21: warning: 'code' is used uninitialized in this function [-Wuninitialized]
 


Sequence of Events
1 - F9 to Build & Run
2 - Enter a value as requested
3 - Presneted with 'file.exe has stopped working' dialog with 'Debug' or 'Close Program' options
3 - Click on 'Close Prgram'
4 - .exe window still open with Message of - Process returned 255 (0XFF) execution time : 62.523 s Press any key to continue
5 - Press a key and the .exe window closes return the log below

-------------- Run: Release in ex0817 (compiler: GNU GCC Compiler)---------------

Checking for existence: C:\Users\Rousseau Associates\Documents\Code Blocks\Test Projects\Learning\ex0817\bin\Release\ex0817.exe
Executing: "C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe" "C:\Users\Rousseau Associates\Documents\Code Blocks\Test Projects\Learning\ex0817\bin\Release\ex0817.exe"  (in C:\Users\Rousseau Associates\Documents\Code Blocks\Test Projects\Learning\ex0817\.)
Process terminated with status 255 (0 minute(s), 20 second(s))
Guys, this is a run time issue. The code isn't going to be what is causing this.

OP wrote:
When I am running code in Code Blocks ... Visual Studio Just-in-time Debugger


My bet is that you are using the default setup for Code::Blocks meaning that you're compiling the code in MingW against its own version of the standard library (which is out of date btw). But when you are running it, it is linking to the version in your system32 folder which I'll bet is the one for Visual Studio or just some other version. Find each of the msvcrt.dll files, the one in system32 and the one in the mingw folder for the C::B installation, then "right click" -> "Properties" -> "Details" tab to compare the version numbers. If you really wanted to confirm this, you can use Process Explorer from SysInternals to actually look at which of the dlls gets loaded into your application: https://technet.microsoft.com/en-us/sysinternals/processexplorer .
Last edited on
Would it be useful to know what the options are in the Visual Studio Just In Time Debugger?
Thanks Computergeek

I have a feeling I did something before this started to happen that may have made some changes. Not sure how but I recall something I'd not seen before popping up and I think I just clicked OK.

Anyway, I will have a go at you suggestions but being new to this I may need a bit more direction if that's OK.

Also, with what you are suggesting, has it the potential to 'break' anything? I wouldn't want to make changes that could make the problem worse?


Thanks
Guys, this is a run time issue. The code isn't going to be what is causing this.

And why not? The code will probably crash because of the misuse of the scanf() function.

OP wrote:

Also, with what you are suggesting, has it the potential to 'break' anything?

Everything that I've described is a read only operation, so no, not if you only do what I have written. We're verifying my theory, not flailing around blind trying to implement an uninformed fix. I could be wrong, in which case we have to go in a different direction.
jib wrote:
And why not? The code will probably crash because of the misuse of the scanf() function.


Damn, you're right, that should be passed in as an address. I wouldn't have expected that to compile with an error like that.

@ OP: I think jib is on to something here.
Last edited on
C:\Windows\System32\ - File Version 7.0.10586.0

There doesn't seem to be one in the Code Blocks folder C:\Program Files (x86)\CodeBlocks\MinGW
I have used the text from the tutorial as written so what should this be written as?

I have used it in the same way for quite a few tutorials prior to the one I experienced the issue with so is there any reason why I wouldn't experience the issue on the first use of this?
Last edited on
You're missing an ampersand from Line 8: scanf("%d",&code);

EDIT: This still doesn't explain why the code that you said worked fine before is suddenly breaking now. Unless the tutorial you are using has mistakes like these all over the place, which is very possible with this language. Link?
Last edited on
EDIT: This still doesn't explain why the code that you said worked fine before is suddenly breaking now. Unless the tutorial you are using has mistakes like these all over the place, which is very possible with this language. Link?

Actually it does. Undefined Behavior is a very strange bedfellow, it could work for days, weeks or even years as you expect, then out of the blue it could crash spectacularly. A small change in the program layout, slightly different compile options, almost anything can be the straw that breaks the camels back.

You should always suspect your program is the cause of the problems, problems with your tools will be very very rare unless you are trying to use the newest aspects of the language.

Which is why I asked for a link to the tutorial site, to confirm that the author of the site is indeed an idiot. You're probably right, I'm just putting too much faith in people who write tutorials being able to code properly.
I am using the c programming for dummies book.

I'll have a look at whether the @ sign is in the specific tutorial tomorrow and update.

Many thanks all or your guidance so far.
Erm ... The '@' character isn't a valid operator character in C or C++, and I'm not sure where you got the impression that we were talking about that. I know this for a fact because it's actually the thing that bothers me the most about both of these languages because it would make SO MUCH MORE SENSE to use "at" instead of "and" when referring to the address of a variable.
Sorry I meant the & symbol.......
So, my laptop did a reset last night I am assuming after an update and I changed the line of code to include the & symbol and all is well......

Strange behaviour indeed!

Is this something to expect when they code is a little out?

And many many thanks for you help help all, much appreciated!
Pages: 12