• C

C Null pointer

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
ghendryAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

morleysCommented:
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
FordreamCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
smediodiaCommented:
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
smediodiaCommented:
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
smediodiaCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.