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

  • SEARCH
  • Home
  • 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 3790812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:22:21+00:00 2026-05-19T12:22:21+00:00

I’ve created an app to solve sudoku grids…but here is my problem : my

  • 0

I’ve created an app to solve sudoku grids…but
here is my problem : my app has some bug and even crashes with my Distribution Configuration for compiling (equivalent to Release Configuration).

Here is the code where it bugs :

- (int*)completeNb:(int[9][9])aMatrix {
    int n, nb;
    int cell[2];
    int *pcell;
    BOOL found = FALSE;
    BOOL pos = FALSE;
    for (int k = 1; k <= 9; k++) {
        n = 0;
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (aMatrix[i][j] == k)
                    n++;
            }
        }
        if (n == 8) {
            found = TRUE;
            nb = k;
            break;
        }
    }
    if (found) {
        for (int l = 0; l < 9; l++) {
            for (int m = 0; m < 9; m++) {
                if ([self isPossibleValue:aMatrix value:nb line:l column:m]) {
                    cell[0] = l;
                    cell[1] = m;
                    pos = TRUE;
                    break;
                }
            }
            if (pos)
                break;
        }
        pcell = cell;
    }
    else {
        pcell = nil;
    }
    return pcell;
}

I have a special sudoku grid where I should find {6,6} as the right position for number 6 (6 should at i=6 and j=6 in the grid). It works perfectly in Debug Configuration, but with Distrib Conf, it seems like I have problem with the l and m vars -> the loop breaks well at l=6 and m=6 (hence, isPossibleValue function seems to work well), but then my cell variable is equal to {1;0}, instead of {6;6} !

I am using this kind of process (returning a cell[2]) with many other functions, and I don’t have any problem with the Distrib Conf.

My second problem, – and this one is provoking the app to crash – is with the following code (again, perfectly working with debug configuration).

- (void)solver:(int[9][9])aMatrix {
    if (!Termine) {
        int *emptyCell = [self firstEmptyCell:aMatrix];
        if (emptyCell != nil) {
            int i = emptyCell[0];
            int j = emptyCell[1];
            for (int k = 1; k <= 9; k++) {
                if ([self isPossibleValue:aMatrix value:k line:i column:j]) {
                    aMatrix[i][j] = k;
                    [self solver:aMatrix];
                    aMatrix[i][j] = 0;
                }
            }
        }
        else {
            if (!Termine) {
                Termine = TRUE;
                for (int i = 0; i < 9; i++)
                    for (int j = 0; j < 9; j++)
                        res[i][j] = aMatrix[i][j];
            }
        }

    }
}

Note : one solution, – I am not sure that’s the best one – is to change optimization level from “fastest, smallest” to “none”.

Thanks for your help !

  • 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-05-19T12:22:22+00:00Added an answer on May 19, 2026 at 12:22 pm

    For the first case the problem is in int cell[2];. It has a local scope, and after you return from the function the memory zone pointed by this array very likely will be reallocated for other needs. A quick solution is to add static specifier:

    static int cell[2];
    

    For the second snippet, make sure that emptyCell each time assigns to i and j values which doesn’t exceed aMatrix bounds [0..8][0..8].

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.