So I have this program that analyzes a file that has entries of coordinates and then puts them in to an array of structs and then prints out a map of either blank spaces represented by "." or a character if there is a corresponding set of coordinates in the input file. Currently the output is printing $ signs and only a handful of the tiles that it should. I know there is a lot that is probably wrong in my code (this is my first program) but any advice/guidance on what is going wrong would be helpful. Thanks
struct COORD{
int xV;
int yV;
char *floor;
};
This is a function that goes through the array created and retus the character tile:
char* onMap(int x, int y, struct COORD z[]){
int arraySize = sizeof(z);
int i;
char *empty = ".";
for(i=0; i<arraySize; i++){
if(z[i].xV == x && z[i].yV == y){
retu z[i].floor;
}
}
retu empty;
}
int main(){
FILE *input = fopen("C:\Users\John\Desktop\input.txt","r");
int x;
int y;
int count = 0;
char tile[5];
struct COORD coordinates[50];
This parses through the file and creates an array of structs (not sure how to deal with the memory allocation though:
while (fscanf(input, "%i %i %s", &x, &y, tile) != EOF) {
coordinates[count].xV = x;
coordinates[count].yV = y;
coordinates[count].floor = tile[(strlen(tile)-1)];
count++;
while(fgetc(input) != 'n'){};
}
int yCoor =1;
int i;
bool mapping = true;
This has to do with printing out the tiles of the map:
while(mapping){
for(i = 1; i<31; i++){
printf("%c", onMap(i, yCoor, coordinates));
if(i==30 && yCoor<30){
printf("%i||n", yCoor);
yCoor++;
i=0;
}//increases the x value & resets y
if(yCoor==30 && i==30){
mapping = false;
}
}
retu 0;
}
}
