Solved

run-time error r6001, -null pointer assign

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
undefined reference to `bswap_128' 9 169
voltage to force translation ? 8 99
Using popen() and gunzip() to open file in HTTPServer 6 65
gdb doesn't stop on breakpoint 2 89
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

789 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