Solved

C Null pointer

Posted on 1997-03-26
5
709 Views
Last Modified: 2010-08-05
I have written a game.  When I quit out of the game, Im left with a NULL POINTER ASSIGNMENT error.

I dont use pointers in the game at alll.

Any ideas.
Game downloadable from http://www.bit.net.au/~ghendry/mystuff.html
0
Comment
Question by:ghendry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Expert Comment

by:morleys
ID: 1249765
You probably use pointers more often than you think. If you make any calls to, for example, printf, you are passing char pointers to output msg strings. It is very hard to write 'c' code w/o using pointers somewhere. What this msg indicates is that you have stored a value using a null pointer. because you are in a small model you have damaged a location in you local memory which is generaly left aside with guard bytes in it so as to diagnose this problem. Had you been working in DOS with a large memory model you would have trashed the interupt table in low memory and crashed the system (it would probably have halted when the access occured). You should be able to run the debugger with a memory watch on location zero and trap the access or try linting your code, it can catch this error a lot, or try using a bounds checker type program which will dynamically catch illegal memory references.
0
 
LVL 1

Accepted Solution

by:
Fordream earned 100 total points
ID: 1249766
The error can occur without any pointer use. Illegal memory using could make the error. About this, morleys said detailedly. What I can say to help, examine your source code with much attention. Wherever, there must be an error as my experience. I had examined the cause of "Null pointer assignment" error for over 5 hours in source code exceeds 3000 lines. At last, a little mistake was there. Maybe the code is not complex, isn't it? Try to find.
 Potent cause I think is usage of scanf. Beginners often mistake in using them. For example, let's see below example source code.

#include <stdio.h>
#include <stdlib.h>

void main()
{
  int num, inputed;
  num = random(1000); /* random function is not ANSI-C compatible as I know. However, it is not important */
  while (1) {
    printf("Input a number you guessed:");
    scanf("%d", inputed);
    if (inputed > num)
      printf("Correct number is larger than %d!\n", num);
    else if (inputed < num)
      printf("Coreect number is smaller than %d!\n", num);
    else break;
  }
  printf("Congulations! You inputed the correct number!\n");
}

 This code seems to have no errors for beginners. But there is an error in scanf using. Arguments to scanf function must be pointer value. That is, you must send address to the 'inputed' variable, not a value of variable to scanf function. So, the line should changed like below:
    scanf("%d", &inputed);

 Excepting this case, there is a lot of cases to cause "Null pointer assignment" error. If you still can't find the error, post the source code to me, or here. I'll examine the code and tell you where did you make an error.
 Bye!

0
 

Expert Comment

by:smediodia
ID: 1249767
Sorry I cant load down your code and revised it for you 'cause I dont have any time at all, but I can give a good trick.
If your programm is under Turbo C, add a watch and type *(char*)0,4m . Then run the program step by step and you will see in the watch that this become 00 00 00 00. When the Null pointer assigment occurs it changes and takes any value. So try to see the error int this place.
See you ghendry.
0
 

Expert Comment

by:smediodia
ID: 1249768
Sorry I cant load down your code and revised it for you 'cause I dont have any time at all, but I can give a good trick.
If your programm is under Turbo C, add a watch and type *(char*)0,4m . Then run the program step by step and you will see in the watch that this become 00 00 00 00. When the Null pointer assigment occurs it changes and takes any value. So try to see the error int this place.
See you ghendry.
0
 

Expert Comment

by:smediodia
ID: 1249769
Sorry I cant load down your code and revised it for you 'cause I dont have any time at all, but I can give a good trick.
If your programm is under Turbo C, add a watch and type *(char*)0,4m . Then run the program step by step and you will see in the watch that this become 00 00 00 00. When the Null pointer assigment occurs it changes and takes any value. So try to see the error int this place.
See you ghendry.
0

Featured Post

Independent Software Vendors: 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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

734 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