When I'm trying to run this code, it gave me this error: "Crash in import". But if I comment out the following lines:

Code:
while(i < c && ddat != -1) 
	{
		
		// file_str_read(ddat,read);
		box[i].name = read;
		
		// box[i].id = file_var_read(did);
		
		i++;
		
		wait(1);
	}



it runs fine. What am I doing wrong?
Here's my code:

Code:
#include <acknex.h>

#define c 3

typedef struct chembox {
	STRING 	*name;
	int 		id;
	int 		state;
} chembox;

void import();

//////////////////////////////////////////////////////////////
chembox box[c];

void import() 
{
	int i = 0, ddat, did;
	STRING *read = "  ";
	
	ddat = file_open_read("ddat.txt");
	did = file_open_read("did.txt");
	
	while(i < c && ddat != -1) 
	{
		
		file_str_read(ddat,read);
		box[i].name = read;
		
		box[i].id = file_var_read(did);
		
		i++;
		
		wait(1);
	}
	
	if(!ddat) file_close(ddat);
	if(!did) file_close(did);
}

void main(void) 
{
	level_load("");
	
	import();
	
	wait(1);
}



And these are two files contain the data:

ddat.txt
Na,Na,Be,

did.txt
0 1 5

Last edited by NNH; 05/15/13 09:57.