TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JACK EVERETT
from: CLIFF RHODES
date: 1997-10-15 11:22:00
subject: Null Pointer

--> Jack Everett wrote to All  <--
JE>OK, I am having a problem here I keep getting a Bad NULL pointer
JE>assignment of some sort....
JE>// For creating monsters for SLAYER
JE> 
JE>#include 
JE>#include 
JE>#include 
JE>#define NUM 3
JE> 
JE>struct monsterlst {
JE>char monstername[80];
JE>int hp;
JE>};
JE>int nummon;
JE>int i;
JE>char getmon[40];
JE>FILE * monster;
JE> 
JE>struct monsterlst monsters[NUM];
JE> 
JE> 
JE>main()
JE>{
JE> 
JE> 
JE> 
JE>clrscr();
JE> 
JE>if (nummon == NUM)
JE>{printf("\nMonster List is full\n");
JE>}
JE> 
JE> 
JE> 
JE>fflush(stdin);
Don't do this--it is undefined. You don't need it.
JE> 
JE>printf("\nWhat is the name of the monster: ");
JE>gets(monsters[NUM].monstername);
monsters[NUM] is not a valid struct for you. C indices run from 0 to 
NUM-1. Since you have NUM defined as 3, your valid indices are 0, 1, 
2. Any other index is an error.
I think you wanted to use nummon here instead of NUM?
Cliff Rhodes
cliff.rhodes@juge.com
crhodes@flash.net
X CMPQwk 1.42 1692 X"As the man is, so is his talk." - Publilius Syrus
--- Maximus/2 3.01
---------------
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.