• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:02
CEST 18:02
KST 01:02
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL55Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event18Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
TRUSTED USDT RECOVERY TECHY FORCE CYBER RETRIEVAL Statistics for vetoed/disliked maps The SCII GOAT: A statistical Evaluation Weekly Cups (June 23-29): Reynor in world title form? PiG Sty Festival #5: Playoffs Preview + Groups Recap
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event RSL: Revival, a new crowdfunded tournament series Korean Starcraft League Week 77 Master Swan Open (Global Bronze-Master 2) [GSL 2025] Code S: Season 2 - Semi Finals & Finals
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
Player “Jedi” cheat on CSL Replays question BW General Discussion Flash Announces Hiatus From ASL BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL20] Grand Finals - Sunday 20:00 CET Small VOD Thread 2.0 [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Trading/Investing Thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread The Games Industry And ATVI
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 670 users

The Big Programming Thread - Page 158

Forum Index > General Forum
Post a Reply
Prev 1 156 157 158 159 160 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
SiPa
Profile Joined July 2010
Germany129 Posts
August 22 2012 07:22 GMT
#3141
What is wrong with this lines of code

#include <glib.h>


GArray *position1;
GArray *position2;
GArray *velocity1;
GArray *velocity2;

position1 = g_array_new(FALSE, FALSE, sizeof (double));
position2 = g_array_new(FALSE, FALSE, sizeof (double));
velocity1 = g_array_new(FALSE, FALSE, sizeof (GArray));
velocity2 = g_array_new(FALSE, FALSE, sizeof (GArray));


Compiler says something about "int" and "int *", also something about a Constant and that "this declaration has no storage class or type specifier".

fearpLug
Profile Joined July 2011
Germany153 Posts
August 22 2012 07:30 GMT
#3142
On August 22 2012 16:22 SiPa wrote:
What is wrong with this lines of code

#include <glib.h>


GArray *position1;
GArray *position2;
GArray *velocity1;
GArray *velocity2;

position1 = g_array_new(FALSE, FALSE, sizeof (double));
position2 = g_array_new(FALSE, FALSE, sizeof (double));
velocity1 = g_array_new(FALSE, FALSE, sizeof (GArray));
velocity2 = g_array_new(FALSE, FALSE, sizeof (GArray));


Compiler says something about "int" and "int *", also something about a Constant and that "this declaration has no storage class or type specifier".



I've not coded in a very long time, but is there supposed to be a "space" between the sizeof function and the brackets of that very function?
And i think a clear compiler message, would help alot =)
SiPa
Profile Joined July 2010
Germany129 Posts
August 22 2012 07:34 GMT
#3143
On August 22 2012 16:30 fearpLug wrote:
Show nested quote +
On August 22 2012 16:22 SiPa wrote:
What is wrong with this lines of code

#include <glib.h>


GArray *position1;
GArray *position2;
GArray *velocity1;
GArray *velocity2;

position1 = g_array_new(FALSE, FALSE, sizeof (double));
position2 = g_array_new(FALSE, FALSE, sizeof (double));
velocity1 = g_array_new(FALSE, FALSE, sizeof (GArray));
velocity2 = g_array_new(FALSE, FALSE, sizeof (GArray));


Compiler says something about "int" and "int *", also something about a Constant and that "this declaration has no storage class or type specifier".



I've not coded in a very long time, but is there supposed to be a "space" between the sizeof function and the brackets of that very function?
And i think a clear compiler message, would help alot =)


Error messages are in german, what i gave you are pretty "clear" translations.
Well, error-codes are:
error C2143 in line 4-7
errors C2040 and 2099 in line 9-12
"IntelliSense: this declaration has no storage class or type specifier" in line 9-12
Also: although i told my compiler (Microsoft VisualStudio 2010 to compile in C, it produces errors even in garray.h
I now believe there's something wrong with my GLib stuff :S
fearpLug
Profile Joined July 2011
Germany153 Posts
Last Edited: 2012-08-22 07:49:46
August 22 2012 07:42 GMT
#3144
Ich würde dir raten, hier nochmal nach zu lesen =)
http://developer.gnome.org/glib/2.31/glib-Arrays.html#GArray
Also so wie ich das sehe, ich habe nämlich grade nochmal durchgeschaut, machst du das richtig..
und MSDN sagt auch lustige sachen über die fehler..

User was warned for this post
SiPa
Profile Joined July 2010
Germany129 Posts
Last Edited: 2012-08-22 07:52:09
August 22 2012 07:49 GMT
#3145
 


#include <stdlib.h>
#include <stdio.h>

#include <glib.h>

int main(void)
{
//Random stuff, that works!
int x = 3;
int y = 2;
int z = 0;
int i = 0;
for (i= 0; i<=100000000; ++i)
{
z = x + y;
printf("%d\n", z);
}

//Stuff that doesnt work
GArray *position1;
GArray *position2;
GArray *velocity1;
GArray *velocity2;

position1 = g_array_new(FALSE, FALSE, sizeof(double));
position2 = g_array_new(FALSE, FALSE, sizeof(double));
velocity1 = g_array_new(FALSE, FALSE, sizeof(GArray));
velocity2 = g_array_new(FALSE, FALSE, sizeof(GArray));

return 0;
}


http://imgur.com/L2Umo

I will commence writing in english, so other ppl dont get annoyed; only thing in german will be the errors...
Sooo
I dont see much difference between this and the example-code, exept for me using double and GArray for sizeof().
fearpLug
Profile Joined July 2011
Germany153 Posts
August 22 2012 07:55 GMT
#3146
so the problem is, that ur compiler wont accept the declaration of the Garray data type, therefore everything that follows wont work. thats what the compiler said ;D
SiPa
Profile Joined July 2010
Germany129 Posts
August 22 2012 07:58 GMT
#3147
any idea what i can do?
I'm kinda lost here...
fearpLug
Profile Joined July 2011
Germany153 Posts
Last Edited: 2012-08-22 08:15:08
August 22 2012 08:02 GMT
#3148
gimme a sec ill install a compiler and test it my self, 5 mins^^
edit: sorry cant seem to get the compiler working at my company pc, damn security and all 8/

Hm if i had to take a guess, its either a wrong compiler and implemented glib or ur compiler isnt liking glib at( buggy ).
U could test to either do a new document and see if this fixes it, or could try another compiler.
If both dont seem to be the error, well then there not much i can think of, cause ur syntax seems 2 be right.
SiPa
Profile Joined July 2010
Germany129 Posts
Last Edited: 2012-08-22 09:55:26
August 22 2012 08:17 GMT
#3149
Hmk, i guess i dont really have to use GLib...it wouldve been just so much easier.
Well thx for your time and all ^^
Pimpmuckl
Profile Joined March 2011
Germany528 Posts
August 22 2012 10:20 GMT
#3150
Hmm stayed in this thread for 12 hours straight, should maybe Grab some food...

Now to my question: I've spent the Last half year working on a OS written in C for a microcontroller on with a Studio called Avr Studio 4 where for example different types of integers (u_int8) and several Hardware specific small "Extras" were used, how well did that teach me "General" C? I'm a bit curios, which Ressource to Test my skills can you guys recommend? Thanks in advance.

Sorry for Bad spelling my german autocorrect runs crazy on my phone TT.
twitter.com/pimpmuckl
waxypants
Profile Blog Joined September 2009
United States479 Posts
Last Edited: 2012-08-24 04:32:52
August 24 2012 04:32 GMT
#3151
On August 22 2012 16:49 SiPa wrote:

...

http://imgur.com/L2Umo

I will commence writing in english, so other ppl dont get annoyed; only thing in german will be the errors...
Sooo
I dont see much difference between this and the example-code, exept for me using double and GArray for sizeof().


All variables need to be declared at the top. So you can you do this:


int main(void)
{
//Random stuff, that works!
int x = 3;
int y = 2;
int z = 0;
int i = 0;
GArray *position1;
GArray *position2;
GArray *velocity1;
GArray *velocity2;

for (i= 0; i<=100000000; ++i)
{
z = x + y;
printf("%d\n", z);
}

position1 = g_array_new(FALSE, FALSE, sizeof(double));
position2 = g_array_new(FALSE, FALSE, sizeof(double));
velocity1 = g_array_new(FALSE, FALSE, sizeof(GArray));
velocity2 = g_array_new(FALSE, FALSE, sizeof(GArray));

return 0;
}


or this:


int main(void)
{
//Random stuff, that works!
int x = 3;
int y = 2;
int z = 0;
int i = 0;
GArray *position1 = g_array_new(FALSE, FALSE, sizeof(double));
GArray *position2 = g_array_new(FALSE, FALSE, sizeof(double));
GArray *velocity1 = g_array_new(FALSE, FALSE, sizeof(GArray));
GArray *velocity2 = g_array_new(FALSE, FALSE, sizeof(GArray));

for (i= 0; i<=100000000; ++i)
{
z = x + y;
printf("%d\n", z);
}

return 0;
}
waxypants
Profile Blog Joined September 2009
United States479 Posts
Last Edited: 2012-08-24 04:47:38
August 24 2012 04:42 GMT
#3152
On August 22 2012 19:20 Pimpmuckl wrote:
Hmm stayed in this thread for 12 hours straight, should maybe Grab some food...

Now to my question: I've spent the Last half year working on a OS written in C for a microcontroller on with a Studio called Avr Studio 4 where for example different types of integers (u_int8) and several Hardware specific small "Extras" were used, how well did that teach me "General" C? I'm a bit curios, which Ressource to Test my skills can you guys recommend? Thanks in advance.

Sorry for Bad spelling my german autocorrect runs crazy on my phone TT.


I'm not sure I entirely understand your question. Are you worried because standard C doesn't have a "u_int8" type? If so, then don't worry, people define their integer types in sorts of ways and you can always define it yourself if you want to use a certain type-scheme. Like: typedef unsigned char uint_8; If your OS class was as hard as mine was, then I'm sure that all that you learned will make you a much better "general" C programmer. To test your skills, find more shit to program
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
August 24 2012 07:25 GMT
#3153
On August 22 2012 19:20 Pimpmuckl wrote:
Hmm stayed in this thread for 12 hours straight, should maybe Grab some food...

Now to my question: I've spent the Last half year working on a OS written in C for a microcontroller on with a Studio called Avr Studio 4 where for example different types of integers (u_int8) and several Hardware specific small "Extras" were used, how well did that teach me "General" C? I'm a bit curios, which Ressource to Test my skills can you guys recommend? Thanks in advance.

Sorry for Bad spelling my german autocorrect runs crazy on my phone TT.


I dabbled in microprocessor programming and while it teaches you a lot about memory management and such, it also teaches you a horrible style that is very focussed on keeping the program and memory footprint small. That is nice in normal C applications but in many cases completely destroys the maintainability of the software.

In normal programming, wasting memory and processing time is in 99.9% of the cases better than writing ugly but efficient code (as long as it's not "leaking memory").

As for testing your skills, i liked http://projecteuler.net/ a lot, though it is not directly for programming and very math focussed but you can improve your problem solving and logic skills through it.
FinnGamer
Profile Blog Joined December 2010
Germany2426 Posts
Last Edited: 2012-08-25 15:03:20
August 25 2012 14:55 GMT
#3154
EDIT: Nevermind changing repaint to paint(getGraphics()); solved my problem
"hopefully swing the favor in your advantage." - Day[9]
TheRabidDeer
Profile Blog Joined May 2003
United States3806 Posts
August 25 2012 21:39 GMT
#3155
So, I am just starting college again (majoring in CS specialized in programming) and I really hate my job at the moment. I was wondering if anybody knew what kind of programming language could net decent part time pay or can nab random jobs for a couple hundred here and there off craigslist or something. My mom was telling me that drupal or wordpress would be a good start and is in high demand, but I wanted to check around and see what other people think.
KainiT
Profile Joined July 2011
Austria392 Posts
August 27 2012 09:24 GMT
#3156
Hey you programming pros, i need some help as I have problems with the sudoku backtracking algorithm.
I am pretty sure my other programm parts are fine and it is just the actual algorithm.

Here is the code:


void solve(int r=0, int c=0, bool forward=1) //solving algorithm
{
cout << "funktionseinstieg"<<endl; //debugging information
if(vordefiniertefelderarray[r][c]==0) //see if field is predefined
{
for(int i=0; i<9; i++)
{
cout <<"schleifenanfang"<<endl; //debugging information
sudfeld[r][c]+=1; //increase value until it fits
feldausgeben(sudfeld); //debugging information
if(!check(r,c,sudfeld[r][c])) //see if value fits
{
cout << "check war negativ"<<endl;
if(c==8&&r==8) //solving should end here if it's already the last field
{
feldausgeben(sudfeld);
return;
}
i=9; //not really sure if i need this, probably not
if(c<8) //go to next field after right value was found
solve(r,c+1,true);
else solve(r+1,0,true);

}
else //go to previous field if right value coul not be found and set current value to 0 again
{
if(sudfeld[r][c]==9)
{
sudfeld[r][c]=0;
if(c>0)
solve(r,c-1,false);
else solve(r-1,8,false);
}
}
}
}
else //if field was predefined
{
cout<<"feldschonbelegt"; //debugging information
if(c==8&&r==8) ////solving should end here if it's already the last field
{
feldausgeben(sudfeld); //debugging information
return;
}
if(forward) //go to next field if forward value is true, previous field if not
{
if(c<8)
solve(r,c+1,true);
else solve(r+1,0,true);
}
else
{
if(c>0)
solve(r,c-1,false);
else solve(r-1,8,false);
}

}
}


I hope you don't mind to much that some function's names are in german. I commented extensively in english to make up for that.
The problems appearantly start when the programm needs to go to a previous field. Possibly involving predefined values.
Thanks in advance.
If somebody would like to see the whole code:

+ Show Spoiler +


#include <iostream>
using namespace std;

int sudfeld[9][9];
int vordefiniertefelderarray[9][9];
void feldausgeben(int feld[9][9])
{
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
cout<<feld[i][j];
if(j==8)
cout << endl;
if(i==8&&j==8)
cout << endl;
}
}
}


bool box(int row, int column, int wert)
{
sudfeld[row][column]=10;
int r= (row/3)*3;
int c= (column/3)*3;
for(int i=r;i<(r+3);i++)
{
for(int j=c;j<(c+3);j++)
{
if(sudfeld[i][j]==wert)
{

cout<<"inboxgefunden";
sudfeld[row][column]=wert;
return true;
}
}
}
sudfeld[row][column]=wert;
return false;
}

bool zeile(int row,int column, int wert)
{
sudfeld[row][column]=10;
for(int i=0;(i<9);i++)
{
if(sudfeld[row][i]==wert)
{
cout<<"inzeilegefunden";
sudfeld[row][column]=wert;
return true;
}
}
sudfeld[row][column]=wert;
return false;
}



bool spalte(int row, int column, int wert)
{
sudfeld[row][column]=10;
for(int i=0;i<9;i++)
{
if(sudfeld[i][column]==wert)
{

cout<<"inspaltegefunden"<<endl;
sudfeld[row][column]=wert;
return true;
}
}
sudfeld[row][column]=wert;
return false;
}


bool check(int row, int column, int wert)
{
if(box(row,column,wert)||zeile(row,column,wert)||spalte(row,column,wert))
{
cout<<"iwogefunden"<<endl;
return true;

}
else
return false;
}


void solve(int r=0, int c=0, bool forward=1) //solving algorithm
{
cout << "funktionseinstieg"<<endl; //debugging information
if(vordefiniertefelderarray[r][c]==0) //see if field is predefined
{
for(int i=0; i<9; i++)
{
cout <<"schleifenanfang"<<endl; //debugging information
sudfeld[r][c]+=1; //increase value until it fits
feldausgeben(sudfeld); //debugging information
if(!check(r,c,sudfeld[r][c])) //see if value fits
{
cout << "check war negativ"<<endl;
if(c==8&&r==8) //solving should end here if it's already the last field
{
feldausgeben(sudfeld);
return;
}
i=9; //not really sure if i need this, probably not
if(c<8) //go to next field after right value was found
solve(r,c+1,true);
else solve(r+1,0,true);

}
else //go to previous field if right value coul not be found and set current value to 0 again
{
if(sudfeld[r][c]==9)
{
sudfeld[r][c]=0;
if(c>0)
solve(r,c-1,false);
else solve(r-1,8,false);
}
}
}
}
else //if field was predefined
{
cout<<"feldschonbelegt"; //debugging information
if(c==8&&r==8) ////solving should end here if it's already the last field
{
feldausgeben(sudfeld); //debugging information
return;
}
if(forward) //go to next field if forward value is true, previous field if not
{
if(c<8)
solve(r,c+1,true);
else solve(r+1,0,true);
}
else
{
if(c>0)
solve(r,c-1,false);
else solve(r-1,8,false);
}

}
}

int main()
{
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
sudfeld[i][j]=0;
}
}

for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
vordefiniertefelderarray[i][j]=0;
}
}


vordefiniertefelderarray[0][5]=2;
vordefiniertefelderarray[1][6]=2;
vordefiniertefelderarray[1][7]=9;
vordefiniertefelderarray[1][8]=8;
vordefiniertefelderarray[2][2]=2;
vordefiniertefelderarray[2][3]=7;
vordefiniertefelderarray[2][6]=5;
vordefiniertefelderarray[2][8]=3;
vordefiniertefelderarray[3][1]=2;
vordefiniertefelderarray[3][4]=8;
vordefiniertefelderarray[3][5]=6;
vordefiniertefelderarray[3][8]=5;
vordefiniertefelderarray[4][2]=1;
vordefiniertefelderarray[4][6]=7;
vordefiniertefelderarray[5][1]=6;
vordefiniertefelderarray[5][2]=9;
vordefiniertefelderarray[5][3]=5;
vordefiniertefelderarray[5][5]=7;
vordefiniertefelderarray[5][6]=4;
vordefiniertefelderarray[6][2]=3;
vordefiniertefelderarray[6][4]=7;
vordefiniertefelderarray[7][0]=9;
vordefiniertefelderarray[7][2]=7;
vordefiniertefelderarray[7][5]=3;
vordefiniertefelderarray[8][1]=4;
vordefiniertefelderarray[8][2]=6;
vordefiniertefelderarray[8][3]=8;
vordefiniertefelderarray[8][4]=2;
vordefiniertefelderarray[8][5]=9;
vordefiniertefelderarray[8][7]=1;

feldausgeben(vordefiniertefelderarray);


for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
sudfeld[i][j]=vordefiniertefelderarray[i][j];
}
}

solve();

feldausgeben(sudfeld);


return 0;
}

With great power comes great responsibility.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
Last Edited: 2012-08-27 10:12:40
August 27 2012 10:12 GMT
#3157
On August 27 2012 18:24 KainiT wrote:
Hey you programming pros, i need some help as I have problems with the sudoku backtracking algorithm.
I am pretty sure my other programm parts are fine and it is just the actual algorithm.

Here is the code:

+ Show Spoiler +

void solve(int r=0, int c=0, bool forward=1) //solving algorithm
{
cout << "funktionseinstieg"<<endl; //debugging information
if(vordefiniertefelderarray[r][c]==0) //see if field is predefined
{
for(int i=0; i<9; i++)
{
cout <<"schleifenanfang"<<endl; //debugging information
sudfeld[r][c]+=1; //increase value until it fits
feldausgeben(sudfeld); //debugging information
if(!check(r,c,sudfeld[r][c]) //see if value fits
{
cout << "check war negativ"<<endl;
if(c==8&&r==8) //solving should end here if it's already the last field
{
feldausgeben(sudfeld);
return;
}
i=9; //not really sure if i need this, probably not
if(c<8) //go to next field after right value was found
solve(r,c+1,true);
else solve(r+1,0,true);

}
else //go to previous field if right value coul not be found and set current value to 0 again
{
if(sudfeld[r][c]==9)
{
sudfeld[r][c]=0;
if(c>0)
solve(r,c-1,false);
else solve(r-1,8,false);
}
}
}
}
else //if field was predefined
{
cout<<"feldschonbelegt"; //debugging information
if(c==8&&r==8) ////solving should end here if it's already the last field
{
feldausgeben(sudfeld); //debugging information
return;
}
if(forward) //go to next field if forward value is true, previous field if not
{
if(c<8)
solve(r,c+1,true);
else solve(r+1,0,true);
}
else
{
if(c>0)
solve(r,c-1,false);
else solve(r-1,8,false);
}

}
}


I hope you don't mind to much that some function's names are in german. I commented extensively in english to make up for that.
The problems appearantly start when the programm needs to go to a previous field. Possibly involving predefined values.
Thanks in advance.
If somebody would like to see the whole code:

+ Show Spoiler +


#include <iostream>
using namespace std;

int sudfeld[9][9];
int vordefiniertefelderarray[9][9];
void feldausgeben(int feld[9][9]
{
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
cout<<feld[i][j];
if(j==8)
cout << endl;
if(i==8&&j==8)
cout << endl;
}
}
}


bool box(int row, int column, int wert)
{
sudfeld[row][column]=10;
int r= (row/3)*3;
int c= (column/3)*3;
for(int i=r;i<(r+3);i++)
{
for(int j=c;j<(c+3);j++)
{
if(sudfeld[i][j]==wert)
{

cout<<"inboxgefunden";
sudfeld[row][column]=wert;
return true;
}
}
}
sudfeld[row][column]=wert;
return false;
}

bool zeile(int row,int column, int wert)
{
sudfeld[row][column]=10;
for(int i=0;(i<9);i++)
{
if(sudfeld[row][i]==wert)
{
cout<<"inzeilegefunden";
sudfeld[row][column]=wert;
return true;
}
}
sudfeld[row][column]=wert;
return false;
}



bool spalte(int row, int column, int wert)
{
sudfeld[row][column]=10;
for(int i=0;i<9;i++)
{
if(sudfeld[i][column]==wert)
{

cout<<"inspaltegefunden"<<endl;
sudfeld[row][column]=wert;
return true;
}
}
sudfeld[row][column]=wert;
return false;
}


bool check(int row, int column, int wert)
{
if(box(row,column,wert)||zeile(row,column,wert)||spalte(row,column,wert))
{
cout<<"iwogefunden"<<endl;
return true;

}
else
return false;
}


void solve(int r=0, int c=0, bool forward=1) //solving algorithm
{
cout << "funktionseinstieg"<<endl; //debugging information
if(vordefiniertefelderarray[r][c]==0) //see if field is predefined
{
for(int i=0; i<9; i++)
{
cout <<"schleifenanfang"<<endl; //debugging information
sudfeld[r][c]+=1; //increase value until it fits
feldausgeben(sudfeld); //debugging information
if(!check(r,c,sudfeld[r][c]) //see if value fits
{
cout << "check war negativ"<<endl;
if(c==8&&r==8) //solving should end here if it's already the last field
{
feldausgeben(sudfeld);
return;
}
i=9; //not really sure if i need this, probably not
if(c<8) //go to next field after right value was found
solve(r,c+1,true);
else solve(r+1,0,true);

}
else //go to previous field if right value coul not be found and set current value to 0 again
{
if(sudfeld[r][c]==9)
{
sudfeld[r][c]=0;
if(c>0)
solve(r,c-1,false);
else solve(r-1,8,false);
}
}
}
}
else //if field was predefined
{
cout<<"feldschonbelegt"; //debugging information
if(c==8&&r==8) ////solving should end here if it's already the last field
{
feldausgeben(sudfeld); //debugging information
return;
}
if(forward) //go to next field if forward value is true, previous field if not
{
if(c<8)
solve(r,c+1,true);
else solve(r+1,0,true);
}
else
{
if(c>0)
solve(r,c-1,false);
else solve(r-1,8,false);
}

}
}

int main()
{
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
sudfeld[i][j]=0;
}
}

for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
vordefiniertefelderarray[i][j]=0;
}
}


vordefiniertefelderarray[0][5]=2;
vordefiniertefelderarray[1][6]=2;
vordefiniertefelderarray[1][7]=9;
vordefiniertefelderarray[1][8]=8;
vordefiniertefelderarray[2][2]=2;
vordefiniertefelderarray[2][3]=7;
vordefiniertefelderarray[2][6]=5;
vordefiniertefelderarray[2][8]=3;
vordefiniertefelderarray[3][1]=2;
vordefiniertefelderarray[3][4]=8;
vordefiniertefelderarray[3][5]=6;
vordefiniertefelderarray[3][8]=5;
vordefiniertefelderarray[4][2]=1;
vordefiniertefelderarray[4][6]=7;
vordefiniertefelderarray[5][1]=6;
vordefiniertefelderarray[5][2]=9;
vordefiniertefelderarray[5][3]=5;
vordefiniertefelderarray[5][5]=7;
vordefiniertefelderarray[5][6]=4;
vordefiniertefelderarray[6][2]=3;
vordefiniertefelderarray[6][4]=7;
vordefiniertefelderarray[7][0]=9;
vordefiniertefelderarray[7][2]=7;
vordefiniertefelderarray[7][5]=3;
vordefiniertefelderarray[8][1]=4;
vordefiniertefelderarray[8][2]=6;
vordefiniertefelderarray[8][3]=8;
vordefiniertefelderarray[8][4]=2;
vordefiniertefelderarray[8][5]=9;
vordefiniertefelderarray[8][7]=1;

feldausgeben(vordefiniertefelderarray);


for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
sudfeld[i][j]=vordefiniertefelderarray[i][j];
}
}

solve();

feldausgeben(sudfeld);


return 0;
}



Well, one problem is that this is a horrible mess.
You seem to try to write a recursive solution while having no clue of how to actually use recursion. You don't backtrack in recursion, you let it do that for you.

Pseudocode since my C and C++ are a little rusty and i don't have a compiler at hand. sudoku_board is a typedef, i think char** should work for that.
+ Show Spoiler +

sudoku_board solve(sudoku_board current_state, int row, int column)
{
// Makes it easier to exit the recursion than checking all the time if it's 8/8.
if (row == 9) return current_state;

// Variable to record the solved state if found
sudoku_board *solved_state = NULL;

// If the current field is predefined, skip straight to the next
if (current_state[row][column] != 0)
{
solved_state = solve(
new_state,
((column == 8) ? row + 1 : row),
((column == 8) ? 0 : column + 1)
);
}

// We need a copy of the current state to work with inside of the recursion so we don't lose the old state
sudoku_board *new_state = copy_state(current_state);

// We test each value from 1-9
// If the recursion lead to a solution (solved_state != NULL) then we don't need to check the remaining values
for (int test_value = 1; ((test_value <= 9) && (solved_state == NULL)); ++test_value)
{
// Update the new state
new_state[row][column] = test_value;

// Check if the test value is valid
if (check_state(new_state))
{
// If it is valid, solve the next field.
solved_state = solve(
new_state,
((column == 8) ? row + 1 : row),
((column == 8) ? 0 : column + 1)
);
}
}
// Memory leaks are bad, mkay?
delete_state(new_state);

// Return any found solutions. If there are no solutions in this recursive branch, it returns the initial value NULL
return solved_state;
}



Also, why do you call one variable "vordefiniertefelderarray" and others "r" and "c". Writing "array" in the name of a variable is pointless, the name of the variable itself should already say what it is. "predefined_fields" says it's an array because, well, it's plural. And whats with your wierd bracket style? I haven't seen that outside of books about bracket styles in at least a decade. Also, skipping brackets in some situations easily leads to hard to read code like the else in this part actually belonging to another if:
+ Show Spoiler +

if(c<8) //go to next field after right value was found
solve(r,c+1,true);
else solve(r+1,0,true);

}
else //go to previous field if right value coul not be found and set current value to 0 again
{
if(sudfeld[r][c]==9)
{
sudfeld[r][c]=0;
if(c>0)
solve(r,c-1,false);
else solve(r-1,8,false);
}
}
KainiT
Profile Joined July 2011
Austria392 Posts
Last Edited: 2012-08-27 10:51:27
August 27 2012 10:27 GMT
#3158
Thank you for the fast answer. I definitely need that kind of help, although I hoped people wouldn't be that harsh with me :D
I'll try to implement your suggestions and then either thank you for your input or come again crying for help^^

Hmm, I gotta say that I don't get your suggestion. How exactly would this recursion do the backtracking if no value fits the current field?

Edit: I kind of get your idea now but it is a completely different algorith -.- Was hoping mine could be fixed somehow. While I know that it's a mess I would still like to know where my errors inside the mess are :D
With great power comes great responsibility.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
August 27 2012 10:50 GMT
#3159
On August 27 2012 19:27 KainiT wrote:
Thank you for the fast answer. I definitely need that kind of help, although I hoped people wouldn't be that harsh with me :D
I'll try to implement your suggestions and then either thank you for your input or come again crying for help^^

Hmm, I gotta say that I don't get your suggestion. How exactly would this recursion do the backtracking if no value fits the current field?


Recursion is hard to explain, it basically works that way:

solve()
|->solve()
|->solve()
|->solve()
....


If one of them doesn't find a solution, it returns NULL. That means it returns to the previous function and that then tries the next number and starts the below functions again. That is why every function call needs it's own state of the game. Once it finds a valid and completed game, it passes that down to the previous function which passes it down to it's parent, etc., until it finally arrives at the first function call.


solve(1,1)
|->1: solve(1,2) => valid
|-> 1: solve(1,3) => invalid
|-> 2: solve(1,3) => valid
|-> 1: solve(1,4) => invalid
....
|-> 1: solve(9,9) => valid, return current state

KainiT
Profile Joined July 2011
Austria392 Posts
August 27 2012 10:58 GMT
#3160
While I do admit obviously that my understanding of backtracking was stupid, I would still like to know why my algorithm doesn't work -.-
I will write the code like you suggested now but not knowing why the previous one didn't work is kind of destroying my nerves right now.
With great power comes great responsibility.
Prev 1 156 157 158 159 160 1031 Next
Please log in or register to reply.
Live Events Refresh
FEL
16:00
Cracov 2025: Qualifier #1
CranKy Ducklings31
Liquipedia
PSISTORM Gaming Misc
15:55
FSL team league: ASP vs PTB
Freeedom1
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
trigger 333
Hui .280
SC2Nice 23
StarCraft: Brood War
Calm 9558
Horang2 2731
Bisu 1917
Jaedong 1733
Flash 1466
Mini 975
Larva 967
firebathero 715
BeSt 582
actioN 383
[ Show more ]
hero 340
Mind 167
Hyun 139
sSak 55
GoRush 31
Mong 27
Rock 16
zelot 15
Dota 2
LuMiX3
Heroes of the Storm
Khaldor534
Other Games
Gorgc3903
singsing3045
B2W.Neo1311
FrodaN1120
Mlord344
Fuzer 337
Lowko307
TKL 164
KnowMe126
Trikslyr60
Organizations
Other Games
EGCTV1185
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• HeavenSC 27
• Kozan
• LaughNgamezSOOP
• AfreecaTV YouTube
• sooper7s
• Migwel
• intothetv
• IndyKCrew
StarCraft: Brood War
• Michael_bg 5
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2956
• WagamamaTV624
• Ler58
League of Legends
• Nemesis8010
Other Games
• Shiphtur29
Upcoming Events
RSL Revival
17h 58m
Clem vs Classic
SHIN vs Cure
FEL
19h 58m
WardiTV European League
19h 58m
BSL: ProLeague
1d 1h
Dewalt vs Bonyth
Replay Cast
2 days
Sparkling Tuna Cup
2 days
WardiTV European League
2 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
[ Show More ]
Replay Cast
5 days
RSL Revival
5 days
FEL
5 days
RSL Revival
6 days
FEL
6 days
FEL
6 days
Liquipedia Results

Completed

BSL 2v2 Season 3
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.