Dunno exactly the problem, but a few pointers:
If you are opening the file for reading change:
> if ( !( fp = fopen(buf, "w+" ) ) )
To
> if ( !( fp = fopen(buf, "r" ) ) )
Also:
char MyArray[1024][1024];
This cannot guarantee you data that's all 0's.
bzero() it out,
loops through it,
for (i=0; i<1024; i++)
MyArray[1024]=0;
or:
if (!str_cmp(string,"End")){
MyArray[i++]=0;
break;
}
One of those should work.
> -----Original Message-----
> From: Saereth Lightsblade [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 17, 2001 11:29 AM
> To: [email protected]
> Subject: Array problem
>
>
>
> 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
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>