Solved

run-time error r6001, -null pointer assign

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

864 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

22 Experts available now in Live!

Get 1:1 Help Now