It actualy works for me. I changed nothing of your insert_data function and it works.
I did guess on what to put in the data and map array, but this was my output:
gold 1 1
pit 0 3
exit 4 0
Could this be right? there was no 'W' in my map array. I filled it from 'A' to 'T'. So that explains why wumpus isn't in the file
Here is the complete code I used to test it:
#include <stdio.h>
FILE * insert_data( FILE * filePtr, char toFind, char word[], char **map, int * data) ;
int main()
{
FILE* outFilePtr;
int data[]={0,0,0,0,0,0,0};//initialize data with 0
char **map;
int i,j;
int num_rows=4;//the max rows for the map array
int num_cols=5;//the max cols for the map array
map = new char*[num_rows];//allocata memory for the rows
for ( i = 0 ; i < num_rows; i++ ) map[i] = new char[num_cols];//allocate memory for the cols
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
{
map[i][j]='A'+((i*5)+j);//fill the map array with the first 20 chars of the alfabet
printf("%c",map[i][j]);//display them on screen
}
printf("\n");
}
data[6]=num_rows;//I have no idea what the data array should be holding
data[5]=num_cols;//I assume it is info on the map array, like max rows and max cols
outFilePtr=fopen("test.txt","w+");//open the file test.txt for the output of the insert_data function
outFilePtr = insert_data( outFilePtr, 'W' , "wumpus", map, data );
outFilePtr = insert_data(outFilePtr, 'G' , "gold", map, data);
outFilePtr = insert_data(outFilePtr, 'P' , "pit", map, data);
outFilePtr = insert_data(outFilePtr, 'E' , "exit", map, data);
for ( i = 0 ; i < num_rows ; i++ ) delete map[i];//remove the map array from memory
delete map;
fclose(outFilePtr);//close the test.txt file
return 0;
}
//Haven't changed anything here
FILE * insert_data( FILE * filePtr, char toFind, char word[], char ** map, int * data)
{
int c=0, d=0;
char line[25];
int row = data[5];
int col = data[6];
while( c < col ) {
while ( d < row ) {
if( map[c][d] == toFind ) {
sprintf( line,"%s %d %d\n", word , d, c);
fputs(line, filePtr);
}
d++;
}
d=0;
c++;
}
return filePtr;
}