Darin Beaudreau
Darin Beaudreau

Reputation: 391

Debug Assertion Failed in C, Not Sure What's Causing It

I'm working on an assignment and I'm pretty much done, but I've run into a roadblock. I'm trying to print out all the "emirp" numbers my program generates, but if I try to print after running my EMIRP finding loop, it causes a Debug Assertion Failed error with this message.

enter image description here

Here's the program source.

http://pastebin.com/f81rE4hb

I'm a C++ guy in transition to using C, so maybe it's a C-specific problem causing it. If you need an explanation of anything, just ask. I'm compiling this with Microsoft Visual Studio 2012 Professional.

Upvotes: 1

Views: 695

Answers (2)

truthseeker
truthseeker

Reputation: 1256

In my case it had to do with mixing unicode main program with non unicode external library written in C. This is what helped to me. Before calling first printf in external library I had to change console mode to ansi. After external library call I had to set mode back to unicode:

#include <io.h>
#include <fcntl.h>

_setmode(_fileno(stdout), _O_TEXT);
....
_setmode(_fileno(stdout), _O_U16TEXT);

Upvotes: 2

barak manos
barak manos

Reputation: 30146

Your problem is that you do emirps++:

  1. You won't be able to free the memory that you've initially allocated, since emirps no longer points to the beginning of that memory.

  2. You most certainly can't go about passing emirps[i] to printf (or any other function for that matter) at that point.

BTW, just noticed that there's a "whole bunch of mallocs" in your code not being freed anywhere...

Upvotes: 0

Related Questions