Visual Studio (C): Debug Assertion failed; .exe has triggered a breakpoint

Hello. I am doing an assignment for my Intro to Programming class. Our instructor provided us with the start of this program, and we were assigned to finish it. My code below runs, but when it gets to "printf("Enter L or R for Large or Regular loaf size.");" the program crashes and gives a Runtime Library error that says:"

Debug assertion failed!
Program:[my program]
File: minkernal\crts\ucrt\inc\corecrt_internal_stdio_input.h
Line: 1240
Expression: buffer!= nullptr
"

I am still very new to C and Visual Studio, so I have absolutely no idea what this means.

I'm not asking anyone to do my assignment, I am asking advice and maybe an explanation of this error.

Thanks in advance,
K


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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>

int
main(void)
{
	char breadType
	char loafSize
	char cookType
	int bakingTime
	int totalTime

	printf("Enter the Type of Bread used\n ");
	scanf(" %c", &breadType);

	printf("Bread Type is %c: \n", breadType);

	switch (breadType) {
	case 'W':
	case 'w':
		printf("White Bread\n");
		break;
	case 'S':
	case 's':
		printf("Sweet Bread\n");
		break;

	default:
		printf("Unknown\n");

	}

	if (breadType == 'w' || 'W')

	{
		printf(" Primary kneading: 15 mins\n");
		printf(" Primary rising: 60 mins\n");
		printf(" Secondary kneading: 18 mins\n");
		printf(" Secondary rising: 20 mins\n");
		printf(" Loaf shaping: 2 seconds\n");
		printf(" Final rising: 75 mins\n");
		printf(" Baking: 45 mins\n");
		printf(" Cooling: 30 mins\n");

	}

	else
	{
		printf(" Primary kneading: 20 mins\n");
		printf(" Primary rising: 60 mins\n");
		printf(" Secondary kneading: 33 mins\n");
		printf(" Secondary rising: 30 mins\n");
		printf(" Loaf shaping: 2 seconds\n");
		printf(" Final rising: 75 mins\n");
		printf(" Baking: 35 mins\n");
		printf(" Cooling: 30 mins\n");

	}

	printf("Enter L or R for Large or Regular loaf size.");
	scanf(" %c", &loafSize);

	if (loafSize == 'L')
	{
		printf("Double loaf size.");
		printf("Baking: .\n");
	}

	else
	{
		printf("Normal loaf size\n\n");
	}


	printf("Enter m or a for auto or manual baking.\n");
	scanf(" %c", &cookType);

	if (cookType == 'm')
	{
		printf("Please remove dough from oven after the Loaf-shaping cycle and prepare for manual baking.\n");
	}

	else
	{

		printf("continue baking\n");
	}

	fflush(stdin);
	getchar();
	return (0);
}
Last edited on
Did you paste the wrong code? This is a C program, though clearly you stated multiple times you are using C++.

The error you are getting means you have made a mistake in your code that can only be detected at runtime. Use your IDE's built-in debugger to find the exact line of your code that is causing the crash, and examine the value of various variables to see what is going on.

By the way, if you haven't already, consider upgrading to Visual Studio 2015.
I'm sorry, I misspoke. Yes, it is C. I think I got confused because when we create new projects we use the empty Visual C++ template.

I am currently using Visual Studio 2015. In class (while writing this code), we use 2010.

To debug, I have been using "Local Windows Debugger." How do I use or enable the built in debugger? Or are we talking about the same thing?

Also, thank you for your prompt assistance and patience with my ignorance.
Yes, we're talking about the same thing. When the program crashes, the IDE should turn into a debugger interface that you can use to examine the state of variables. You can also set a breakpoint right before where you know it crashes. There are plenty of useful guides online for how to use the debugger if you're not familiar.
Great. Thanks for your help, LB!
Okay, I ran the debugger and the error is on the last line (19 in this post) of stdio.h, which I pasted the last section of below.

Like I have mentioned already, I am a beginner, so I'm afraid to alter this file without knowing what I'm doing. Is this something I may have accidentally altered without noticing, or something else?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    #if defined _DEBUG && defined _CRTDBG_MAP_ALLOC
        #pragma pop_macro("tempnam")
    #endif

    _Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_fcloseall) _ACRTIMP int   __cdecl fcloseall(void);
    _Check_return_     _CRT_NONSTDC_DEPRECATE(_fdopen)    _ACRTIMP FILE* __cdecl fdopen(_In_ int _FileHandle, _In_z_ char const* _Format);
    _Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_fgetchar)  _ACRTIMP int   __cdecl fgetchar(void);
    _Check_return_     _CRT_NONSTDC_DEPRECATE(_fileno)    _ACRTIMP int   __cdecl fileno(_In_ FILE* _Stream);
    _Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_flushall)  _ACRTIMP int   __cdecl flushall(void);
    _Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_fputchar)  _ACRTIMP int   __cdecl fputchar(_In_ int _Ch);
    _Check_return_     _CRT_NONSTDC_DEPRECATE(_getw)      _ACRTIMP int   __cdecl getw(_Inout_ FILE* _Stream);
    _Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_putw)      _ACRTIMP int   __cdecl putw(_In_ int _Ch, _Inout_ FILE* _Stream);
    _Check_return_     _CRT_NONSTDC_DEPRECATE(_rmtmp)     _ACRTIMP int   __cdecl rmtmp(void);

#endif // !__STDC__



_CRT_END_C_HEADER
Last edited on
By the way, line 36 doesn't do what you think it does - the condition will always be true. Compiler sees it as ((breadType == 'w') || ('W'))
LB, do you know anything about my last post?
The error is not in the code of any header you are using, it is in code you have written yourself. The debugger can be confusing sometimes - remember that since you are using functions from that header, a mistake in your code can cause the code in that header to malfunction. You should step up the call stack until it gets to a line of code you have written.
I get compile errors with what you posted.
Lines 10-14 all need to be terminated with a ;

After making those corrections, the program runs for me with the values I used (W L m).
What values did you use that made it crash?

If you're having trouble locating the line of code where your program is crashing, please post the contents of the call stack window.





Topic archived. No new replies allowed.