ShaolinMist
12-05-2011, 01:41 PM
Hi I'm a beginner programmer and I am trying to read my txt file of " 1's and 0's" to create my maze wall but I keep getting "fopen_s and fscanf_s not declared in scope" error. I am using Xcode on mac can you help me? Here's my code:
void init() {
FILE *ifp;
glClearColor(1, 1, 1, 1); // set backgoround color as white
glShadeModel(GL_SMOOTH); // smooth mode
glEnable(GL_DEPTH_TEST); // enable depth mode
person.x = 5;
person.y = 5;
person.z = 10;
person.direction = 180;
b3rdParty = false;
viewPortHeight = WINDOW_HEIGHT;
viewPortWidth = WINDOW_WIDTH;
fopen_s(&ifp, "stage1.txt", "r");
fscanf_s(ifp, "%d %d ", &map_length, &map_width);
mappings = (int**)malloc(sizeof(int*) * map_width);
for(int i = 0; i < map_width; i++) {
mappings[i] = (int*)malloc(sizeof(int) * map_length);
}
for(int i = 0; i < map_width; i++) {
for(int j = 0; j < map_length; j++) {
fscanf_s(ifp, "%d ", &mappings[i][j]);
// starting point of the user
if(mappings[i][j] == 10) {
person.x = i * BLOCK_SIZE + (BLOCK_SIZE / 2);
person.y = j * BLOCK_SIZE + (BLOCK_SIZE / 2);
printf("Start here: %d %d\n", i, j);
}
}
}
ground_length = map_length * BLOCK_SIZE;
ground_width = map_width * BLOCK_SIZE;
printf("Start!\n");
fclose(ifp);
}
void init() {
FILE *ifp;
glClearColor(1, 1, 1, 1); // set backgoround color as white
glShadeModel(GL_SMOOTH); // smooth mode
glEnable(GL_DEPTH_TEST); // enable depth mode
person.x = 5;
person.y = 5;
person.z = 10;
person.direction = 180;
b3rdParty = false;
viewPortHeight = WINDOW_HEIGHT;
viewPortWidth = WINDOW_WIDTH;
fopen_s(&ifp, "stage1.txt", "r");
fscanf_s(ifp, "%d %d ", &map_length, &map_width);
mappings = (int**)malloc(sizeof(int*) * map_width);
for(int i = 0; i < map_width; i++) {
mappings[i] = (int*)malloc(sizeof(int) * map_length);
}
for(int i = 0; i < map_width; i++) {
for(int j = 0; j < map_length; j++) {
fscanf_s(ifp, "%d ", &mappings[i][j]);
// starting point of the user
if(mappings[i][j] == 10) {
person.x = i * BLOCK_SIZE + (BLOCK_SIZE / 2);
person.y = j * BLOCK_SIZE + (BLOCK_SIZE / 2);
printf("Start here: %d %d\n", i, j);
}
}
}
ground_length = map_length * BLOCK_SIZE;
ground_width = map_width * BLOCK_SIZE;
printf("Start!\n");
fclose(ifp);
}