Thread: File read problem

  1. #1
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320

    File read problem

    Ok for some reason this code is crashing while I am loading the path for the pics in no idea why really... I do know all the functions for the NPC class work I tested those first thing... I just don't see any reason it should crash while reading art/man.bmp into a 250 char array or that is where it is crashing apparently. Ideas on what might be causing this problem?

    Code:
           char input[250];
           ofstream feed;
           ifstream  load;
    Code:
    load>>NumNPC;
    	feed<<"NUM NPC: "<<NumNPC<<endl;
    	npclist = new NPC*[NumNPC];
    	int nx,ny,sn;
    	for(int lnpc = 0;lnpc < NumNPC;lnpc++)
    	{
    		load>>nx>>ny>>sn;
    		feed<<"NX NY SN "<<nx<<" "<<ny<<" "<<sn<<endl;
    		npclist[lnpc]->SetXYSN(nx,ny,sn);
    		load>>input;//crashes here
    		feed<<"IGPIC: "<<input;
    		npclist[lnpc]->SetIGPic(input);
    		load>>input;
    		feed<<"DIAPIC: "<<input;
    		npclist[lnpc]->SetDialoguePic(input);
    	}
    	feed.close();
    Part of the load file where the problem is occuring.
    Code:
    #NPC  2
            5   5        0             art/man.bmp          art/ness_t.bmp
            9   9        1             art/woman.bmp        art/darokin.bmp 
    #ENDNPC
    The feedback file I have it dumping into.
    Code:
    NUM NPC: 2
    NX NY SN 5 5 0
    Bah stupid me left a line out since I was using a NPC ** I forgot to make the loop sorry about that. Here is what I was missing.
    Code:
    load>>NumNPC;
    	feed<<"NUM NPC: "<<NumNPC<<endl;
    	npclist = new NPC*[NumNPC];
    	for(int m=0;m<NumNPC;m++)
    	{
    		npclist[m] = new NPC;
    	}
    	int nx,ny,sn;
    Last edited by ~Kyo~; 08-26-2005 at 05:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Read File Problem
    By lonewolf367 in forum C Programming
    Replies: 11
    Last Post: 11-30-2005, 10:32 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM