Hi guys , I'm giving you the full C# project I have uploaded , since I'm working with windows form , so you can see the source code and run it .
http://www.sendspace.com/file/u7z6h0

And now , to explain my problem .
The program I wanted to make is sudoku solver . Now , It's something I'm only making for fun , so if you think it's going to take you too much time to help me , do not give yourself a hard time , it's enough that you even read this post .
Now , in this code , there are 2 main functions

void upisi( int i, int j, int p)

this function is the first one that gets called , it takes parameters i and j for
rows and columns , and p is the number that is being checked .
The logic I used for solving was my own , so please don't make me feel embarassed :-D , I'm sure there are many better ways for solving this , but I wanted to try it on my own ..
So basically , the sudoku fields are 2-dimensional textBox array ,so it acts like a matrix
and I'm starting from field at 0,0 .
First , I'm checking if I'm out of bounds (second coordinate bigger than 8 ) , if so , go into next row (++i) .
If I'm not out of bound , then check if the field is enabled (enabled fields are those that need to be filled) , if not go to the next field .
If I'm not out of bounds , and the field is enabled , then check to see if the number I'm testing is less then 10 (1-9 ), if that condition is satisfied , then again check if the textbox CAN be filled with that number (if rows , columns and it's square do not contain the same number ).
If all those conditions are fullfiled , the text box is filled with that number , and the program moves on to the next field , however , if the number is not less than 10, that means that the field can not contain anything from 1 to 9 , so I need to go back at the previous field and try another combination
thats where I call the function

void vrati(int i, int j)
It simply checks what the number on the field is and tries another possible , if this number also exceeds the bounds ( not < 10), than it will simply call itself again until it can fulfill the condition .
If the number is good to go , it calls the function void upisi( int i, int j, int p) and this function fills that textbox with the number and moves on .

Now , I'm sorry for this long intro , but I wanted to clear this code up, because I know I'm pretty messy when it comes to code writing .
This code seems to be working quite well , BUT when I try it on some easy sudokus , it gives me the stack overflow error and crashes .
The code is working perfectly fine even if I do not enter a single number , but when I try to solve some puzzled , it crashes .
If anyone could help me with this I would appreciate this so much , it's not important for me to have the sudoku solver , but to understand where my mistake was .
Thanks in advance !
Stefan

I ve seen your code, I can have a deeper look at it but in 4 days from now on. If you find the error than post it so that we actually know that youre done with it ...

I'm looking for the mistake myself , but it always seems like I'm at the dead end . I will post if I solve it :)

Hey Felix,

So I scanned your post (currently in the office), but I will say this. Anytime I've blown a Stack Overflow error, it's been with recursive calls that don't increment or termiante properly.

One example would be the index doesn't increment properly, so it continues to recursively call until the error is blow. Once again, haven't had a chance to look at your code yet, but let me ask you two questions
- Do you have an recursive calls?
- Have you checked your loops (like "for" or "while") to make sure they are incrementing properly?

I'll try and remember to look at your code when I get back from office tonight (funny you did this project, it was a final for one of my classes in college, except, a team member did the solver, I did all the GUI work and merging ... needless to say, they got the easy job, LOL)

I do have a recursive call , however when I try to solve the entirely (or barely ) empty sudoku "board" the code runs just fine , and solves it without any problems , but when I insert a bit more data it gives the stack overflow . I was also busy these days so I wasn't around trying to figure out what could be wrong with the code .
Anyway , if you grab some time check out the code and maybe you can figure out what could be wrong .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.