PDA

View Full Version : Problem reading file for maze game!!



ShaolinMist
12-05-2011, 02: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 ", &amp;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);
}

carsten neumann
12-05-2011, 03:09 PM
I don't see what that has to do with OpenGL (the topic of these forums)? You are probably better off asking these kinds of questions on a general C programming forum.

Functions like fscanf_s and fopen_s that look like standard C library functions with an extra "_s" are not portable. They are a Microsoft extension that is intended to provide extra security - probably by making additional checks on the arguments etc.

For portable programs or ones that are developed on non Microsoft platforms they should (or must) be avoided.

ShaolinMist
12-05-2011, 10:24 PM
FYI this maze game IS OpenGL! But thank you for your help. You know, when u guys answer questions, do you always have to add a smart remark or comment?? It is very discouraging for beginners who just need alil help.

Alfonse Reinheart
12-05-2011, 11:02 PM
FYI this maze game IS OpenGL!

That doesn't mean the question itself is about OpenGL. Just because your application uses OpenGL doesn't mean that every problem you encounter in that app is about OpenGL.

This forum is for talking about OpenGL. That includes questions about the OpenGL parts of applications. Your problem has nothing to do with OpenGL itself, and it's perfectly reasonable to point that out.

ShaolinMist
12-05-2011, 11:27 PM
You're an a**.

Alfonse Reinheart
12-06-2011, 01:49 AM
Maybe, but that doesn't mean I'm wrong ;)

carsten neumann
12-06-2011, 08:15 AM
FWIW I put a question mark behind the statement giving you the chance to make it clear what the connection to OpenGL was in case I missed it. I also made a suggestion to ask for help in a place that is more likely to give you an answer.
I'd like to repeat that suggestion here, because I for one are not going to answer questions of folks that can not accept if someone points out that they likely made a mistake without calling names.

BionicBytes
12-06-2011, 08:48 AM
because I for one are not going to answer questions of folks that can not accept if someone points out that they likely made a mistake without calling names

I second that too.

glfreak
12-06-2011, 10:42 AM
You know, when u guys answer questions, do you always have to add a smart remark or comment??

Yes this is unfortunately very common here. Well this is the nerdy way! :)


This forum is for talking about OpenGL. That includes questions about the OpenGL parts of applications. Your problem has nothing to do with OpenGL itself, and it's perfectly reasonable to point that out.

Even if you ask a very relevant OpenGL question, you will face the same fate of getting "smart comments"-decorated replies, very likely from the same group. :)

ShaolinMist
12-11-2011, 07:03 PM
Lmbo! I guess I forgot I was talking to nerds!