Results 1 to 10 of 10

Thread: Problem reading file for maze game!!

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    15

    Problem reading file for maze game!!

    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:

    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);
    }
    What in the.....????!!

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: Problem reading file for maze game!!

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    15

    Re: Problem reading file for maze game!!

    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.
    What in the.....????!!

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,677

    Re: Problem reading file for maze game!!

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    15

    Re: Problem reading file for maze game!!

    You're an a**.
    What in the.....????!!

  6. #6
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,677

    Re: Problem reading file for maze game!!

    Maybe, but that doesn't mean I'm wrong

  7. #7
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: Problem reading file for maze game!!

    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.

  8. #8
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Problem reading file for maze game!!

    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.

  9. #9
    Senior Member Frequent Contributor
    Join Date
    May 2001
    Posts
    566

    Re: Problem reading file for maze game!!

    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.

  10. #10
    Junior Member Newbie
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    15

    Re: Problem reading file for maze game!!

    Lmbo! I guess I forgot I was talking to nerds!
    What in the.....????!!

Similar Threads

  1. Reading a ppm file
    By Rocketman in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-24-2010, 09:15 AM
  2. Reading a 3ds max file
    By the_transltr in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-25-2009, 10:29 PM
  3. Replies: 12
    Last Post: 05-25-2005, 12:42 PM
  4. Error Reading File BMP File Size ?
    By Olumide in forum OpenGL: Advanced Coding
    Replies: 13
    Last Post: 01-31-2002, 10:57 AM
  5. MAZE GENERATION PROBLEM PLEASE HELP
    By swyitch in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-02-2001, 11:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean