Solved

run-time error r6001, -null pointer assign

Posted on 1997-11-20
1
1,676 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
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.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

680 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