Solved

run-time error r6001, -null pointer assign

Posted on 1997-11-20
1
1,600 Views
Last Modified: 2012-05-04
I get this error when I run the program (exe) from the command line, but not when I run from inside QuickC and compile into memory. My program has FILE *output; output = fopen("prog07.dat", "a"); print some stuff.... fclose(output); what is my trouble ??
0
Comment
Question by:rogerj
1 Comment
 
LVL 3

Accepted Solution

by:
LucHoltkamp earned 50 total points
ID: 1256386
The fact that a program works when loaded in the debugger but fails when executed stand-alone happens more often.

Never the less, there seems to be a serious problem in your code: you use a pointer wich is not initialized. Check your code, and make sure every pointer you use is initialized. For example:
output = fopen("prog07.dat", "a");
fopen will return NULL when it fails. You should always check the return value of fopen:
if (NULL == (output = fopen("prog07.dat", "a")))
{
  puts("Cannot open \"prog07.dat\"");
  exit(1);
}

Some debug tricks to help you:
1) If you use the DOS platform then the usage of a NULL pointer will overwrite a piece of data in the start of the data segment (DS:0000). The program checks to see if this data has changed, and if it has, it will generate your runtime error. You can leave a inspector open in the debugger on this adres (DS:0000) while your stepping through the program. When you see the data change, the NULL pointer assignment has just happend.
2) You can compile for WIN32, then the debugger will halt your program at the moment the NULL pointer assignment occurs. This is a very handy feature of WIN32, but I don't know if you can compile for WIN32 with QuickC
.luc.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now