Greetings list,
I'm having a problem with a function I wrote. What it
is supposed to do is open a set file, read in each line
storing the data from each line in element i of an array until it finds the
word "End" and then display the results. Everything compiles fine but I get
a seg fault whenever i execute the command. This is the actual function:
void remove_from_roster(CHAR_DATA *ch)
{
char buf[1024];
FILE *fp;
char *string;
char MyArray[1024][1024];
int i;
string = "End";
sprintf(buf, "%s%s.dat", DATA_DIR,FILENAME);
if ( !( fp = fopen(buf, "w+" ) ) )
{
bug( "Could not open data file.", 0 );
return;
}
i = 0;
for ( ; ; )
{
if (feof(fp))
string = "End";
else
fgets(string,MSL,fp);
if (string == NULL)
break;
if (!str_cmp(string,"End"))
break;
strcpy(MyArray[i],string);
i++;
}
for (i = 0; MyArray[i] != NULL; i++)
send_to_char(MyArray[i],ch);
fclose(fp);
return;
}
The file it's loading from in ../data/testfile
and the contents look like this:
testline1
testline2
End
If anyone see's what I'm doing wrong please let me know.
Think of something witty, and put it -Here-
Saereth
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com