Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8954739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:22:41+00:00 2026-06-15T14:22:41+00:00

I write a procedure tha must to write 2d-array to a file. Here’s code:

  • 0

I write a procedure tha must to write 2d-array to a file. Here’s code:

void Level::loadLevel(){
    int levelmap[15][9];
    FILE *fp = fopen("resources/lvls/loc1.map", "wb");  
    for (int i=0;i<=15;i++){
        for(int j=0;j<=9;j++){
            levelmap[i][j]=i+j;
            }
    }
    char asd[255];

    for (int i=0;i<=15;i++){
        for(int j=0;j<=9;j++){
            char *buffer=itoa(levelmap[i][j],asd,1);
            fwrite(buffer,2,sizeof(buffer),fp);
            };
        };
    fclose(fp);
 }

it’s compiling, but on call this function application is crashed. i call it as menu_selector attribute of cocs2d-x menu item. Why is it crashes?

Update: Changed to file streams ad works excellent

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:22:42+00:00Added an answer on June 15, 2026 at 2:22 pm
    char *buffer=itoa(levelmap[i][j],asd,1);
    

    The last param of itoa is base. It should be 10 instead of 1 (see http://www.cplusplus.com/reference/cstdlib/itoa/ )


    void Level::loadLevel(){
        int levelmap[15][9];
        FILE *fp = fopen("resources/lvls/loc1.map", "wb");  
        for (int i=0;i<=15;i++){
            for(int j=0;j<=9;j++){
                levelmap[i][j]=i+j;
                }
        }
    

    If i == 15 and j == 9, you exceed array’s boundaries (levelmap[15][9] means levelmap[0..14][0..8])

    Change conditions in loops to i < 15 and j < 9.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a stored procedure to increment the value of an int
I am trying to write a procedure in Inno setup code using default values
I write stored procedure for update. create procedure sp_videos_updateviews (@videoid varchar(50),@ret int output) as
How would I write a procedure that would build this array such that I
I want to write a procedure to perform a delete for the following i
I'm trying to write an procedure that does something after 2 objects are returned
I'm trying to write a procedure for a baseball program that will use multiple
I am new stored procedures and trying to write a procedure to duplicate user(by
I'm looking to write a stored procedure that takes as a parameter a string
I'm trying to write a stored procedure in SQL that will : Make a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.