Originally Posted by
jimblumberg
Post your current code, all of it!
You should be using "counter" not "sizeof(coordinates)" in that for loop, counter holds the number of records read.
Jim
That is all my code currently, I deleted all my test loops... feeling really stupid now. I dont think the array is even being filled.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
struct COORD{
int xV;
int yV;
char *floor;
};
char *onMap(int x, int y, struct COORD z[]){
int arraySize = sizeof(z);
int i;
for(i=0; i<arraySize; i++){
if(z[i].xV == x && z[i].yV == y){
return z[i].floor;
}
}
return ".";
}
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];
while (fscanf(input, "%i %i %s", &x, &y, tile) != EOF) { //creates an struct array of all map positions
coordinates[count].xV = x;
coordinates[count].yV = y;
coordinates[count].floor = tile[(strlen(tile)-1)];
count++;
while(fgetc(input) != '\n'){};
}
int j;
for(j = 0; j<count; j++){
printf("%i %i %s\n", coordinates[j].xV, coordinates[j].yV, coordinates[j].floor);
}
int yCoor =1;
int i;
bool mapping = true;
while(mapping)
{
for(i = 1; i<31; i++){
printf("%s", 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;
}
}
}
return 0;
}