• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 14:35
CET 20:35
KST 04:35
  • 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
RSL Revival - 2025 Season Finals Preview7RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3
StarCraft 2
General
RSL Revival - 2025 Season Finals Preview Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced
Tourneys
RSL Offline Finals Info - Dec 13 and 14! Tenacious Turtle Tussle 2025 RSL Offline Finals Dates + Ticket Sales! Sparkling Tuna Cup - Weekly Open Tournament StarCraft2.fi 15th Anniversary Cup
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 504 Retribution Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ [BSL21] RO8 Bracket & Prediction Contest BW General Discussion FlaSh on: Biggest Problem With SnOw's Playstyle Let's talk about Metropolis
Tourneys
[ASL20] Grand Finals [BSL21] RO8 - Day 2 - Sunday 21:00 CET [BSL21] RO8 - Day 1 - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Fighting Spirit mining rates Current Meta
Other Games
General Games
Dawn of War IV Path of Exile Stormgate/Frost Giant Megathread Awesome Games Done Quick 2026! Nintendo Switch Thread
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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine US Politics Mega-thread YouTube Thread European Politico-economics QA Mega-thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
TL+ Announced Where to ask questions and add stream?
Blogs
How Sleep Deprivation Affect…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1781 users

c++ help?

Blogs > tossinYoSalad
Post a Reply
Normal
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
Last Edited: 2009-10-14 02:15:20
October 14 2009 02:01 GMT
#1
Ok, so this project is due in 2 hours, and I've been working on it all day. It's pretty much done but it's just not working and I just can't stare at it any more. Can someone help?

The project is basically analyzing contiguous spaces in a two-dimensional array (find the blobs). A blob is 2 or more contiguous spaces in the array. I've figured out how to find the blobs using a stack, and I think I implemented it correctly but it's not working for some reason. The code hangs within the while loop so I'm assuming something in there is wrong. here is the code:

http://pastebin.com/d30e116f3

^^pastebin now.

I know its way over commented, I'm a total noob at c++ (mostly code in java,asm, and python) and it got confusing with braces and shit. I also know this could be done way more efficiently but I don't really care at this point, I just need it to work. The following DOES work: importing grid from text file, displaying the grid, and everything else. the above method hangs in the while loop and I can't figure out why. Help PLEASE!

b3h47pte
Profile Blog Joined May 2007
United States1317 Posts
Last Edited: 2009-10-14 02:05:19
October 14 2009 02:05 GMT
#2
Use http://pastebin.com/
it hurts my eyes looking at that...>>
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
October 14 2009 02:06 GMT
#3
with no identation its impossible to read anything
"When the geyser died, a probe came out" - SirJolt
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
October 14 2009 02:06 GMT
#4
http://pastebin.com/m588911d8

sorry, wish tl had code tags lol.
Eti307
Profile Blog Joined March 2004
Canada3442 Posts
October 14 2009 02:08 GMT
#5
Wow that's way to messy, sorry I'm not touching that
was the //startif //endif comments really necessary? lol

Where exactly does it hang? use the debugger, might give you a clue
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
October 14 2009 02:12 GMT
#6
On October 14 2009 11:08 Eti307 wrote:
Wow that's way to messy, sorry I'm not touching that
was the //startif //endif comments really necessary? lol

Where exactly does it hang? use the debugger, might give you a clue


the startif endif i put it so i could check and see if i was missing a bracket when i was fixing syntax errors. i can clean it real fast.
yenta
Profile Blog Joined April 2006
Poland1142 Posts
October 14 2009 02:12 GMT
#7
What are the INPUTs and OUTPUTs of this function supposed to be?
Trutacz Practice Discord - https://discord.gg/PWF7Pv
Eti307
Profile Blog Joined March 2004
Canada3442 Posts
October 14 2009 02:16 GMT
#8
On October 14 2009 11:12 tossinYoSalad wrote:
Show nested quote +
On October 14 2009 11:08 Eti307 wrote:
Wow that's way to messy, sorry I'm not touching that
was the //startif //endif comments really necessary? lol

Where exactly does it hang? use the debugger, might give you a clue


the startif endif i put it so i could check and see if i was missing a bracket when i was fixing syntax errors. i can clean it real fast.


instead of doing that just type in both brackets each and everytime you are using something with brackets. Prevents those type of errors
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
Last Edited: 2009-10-14 02:21:40
October 14 2009 02:16 GMT
#9
On October 14 2009 11:12 yenta wrote:
What are the INPUTs and OUTPUTs of this function supposed to be?


all it does is count the number of blobs and keep track of the recursion depth. numBlobs is incremented immediately after the while loop and recDepth is incremented at the end of the function.

there is no input it acts on a grid held in the class (just a two-dim array of ints) its called gridCopy. theGrid is the same thing only its an arr of chars (this teacher is psycho, i had to do it this way)
i know its a horrible implementation believe me.
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
October 14 2009 02:17 GMT
#10
On October 14 2009 11:16 Eti307 wrote:
Show nested quote +
On October 14 2009 11:12 tossinYoSalad wrote:
On October 14 2009 11:08 Eti307 wrote:
Wow that's way to messy, sorry I'm not touching that
was the //startif //endif comments really necessary? lol

Where exactly does it hang? use the debugger, might give you a clue


the startif endif i put it so i could check and see if i was missing a bracket when i was fixing syntax errors. i can clean it real fast.


instead of doing that just type in both brackets each and everytime you are using something with brackets. Prevents those type of errors


ya i do, i also needed to put a a few lines in specific places at the end and there were 5 braces in a row at the end lol.
yenta
Profile Blog Joined April 2006
Poland1142 Posts
October 14 2009 02:29 GMT
#11
On October 14 2009 11:16 tossinYoSalad wrote:
Show nested quote +
On October 14 2009 11:12 yenta wrote:
What are the INPUTs and OUTPUTs of this function supposed to be?


all it does is count the number of blobs and keep track of the recursion depth. numBlobs is incremented immediately after the while loop and recDepth is incremented at the end of the function.

i know its a horrible implementation believe me.


Rewrite it like this:

RECURSIVE CALLER
Initialize count
Initialize array of array with flags (w/e you want)
FOR( 0...x )
FOR( 0..y )
if point @ x,y is unchecked & x.y is a space, call recursive worker
//FOR
//FOR
return w/e

RECURSIVE WORKER ( root, current_x, current_y, pointer to 2D array, ref to count )
base case:
return if out of bounds
return if space you're looking has been marked 'looked at'
recursive case:
count adj spaces by calling self with: ( x-1,y ), ( x+1, y), (x, y+1), (x, y-1) + diagonals if they count.
if adj spaces > 0 & root == true, increment counter //endif
mark current space as read
END
Trutacz Practice Discord - https://discord.gg/PWF7Pv
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
October 14 2009 02:34 GMT
#12
On October 14 2009 11:29 yenta wrote:
Show nested quote +
On October 14 2009 11:16 tossinYoSalad wrote:
On October 14 2009 11:12 yenta wrote:
What are the INPUTs and OUTPUTs of this function supposed to be?


all it does is count the number of blobs and keep track of the recursion depth. numBlobs is incremented immediately after the while loop and recDepth is incremented at the end of the function.

i know its a horrible implementation believe me.


Rewrite it like this:

RECURSIVE CALLER
Initialize count
Initialize array of array with flags (w/e you want)
FOR( 0...x )
FOR( 0..y )
if point @ x,y is unchecked & x.y is a space, call recursive worker
//FOR
//FOR
return w/e

RECURSIVE WORKER ( root, current_x, current_y, pointer to 2D array, ref to count )
base case:
return if out of bounds
return if space you're looking has been marked 'looked at'
recursive case:
count adj spaces by calling self with: ( x-1,y ), ( x+1, y), (x, y+1), (x, y-1) + diagonals if they count.
if adj spaces > 0 & root == true, increment counter //endif
mark current space as read
END


thanks alot, what do you mean by root though? and because the 2d array is a class var i dont need to pass it though do i?
Slithe
Profile Blog Joined February 2007
United States985 Posts
Last Edited: 2009-10-14 02:39:04
October 14 2009 02:38 GMT
#13
I only very briefly skimmed it so I may be way off, but it looks like your bounds checking is wrong?

Your Code:
if (rowPtr-1 > 0)
if(rowPtr+1 < theGrid.getRows())

I'm assuming you're trying to make sure that 0 <= rowPtr < theGrid.getRows(). If that's the case, then shouldn't it be:

if (rowPtr+1 > 0)
if(rowPtr < theGrid.getRows())
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
Last Edited: 2009-10-14 02:50:38
October 14 2009 02:42 GMT
#14
On October 14 2009 11:38 Slithe wrote:
I only very briefly skimmed it so I may be way off, but it looks like your bounds checking is wrong?

Your Code:
if (rowPtr-1 > 0)
if(rowPtr+1 < theGrid.getRows())

I'm assuming you're trying to make sure that 0 <= rowPtr < theGrid.getRows(). If that's the case, then shouldn't it be:

if (rowPtr+1 > 0)
if(rowPtr < theGrid.getRows())


uhh you were sorta right, but you DID point out an error it needs to be if(rowPtr-1 >= 0) otherwise itll never enter those code segments on the leftmost or rightmost bounds.

but yes it needs to be within the bounds of [0,theGrid.getRows()], but because it can only exceed the left bound on a -1, and it can only exceed the right bound on a +1 i ommited those calls.

fixed it to that and still didnt work. I think its a stack error in the original code, but now im rewriting with yenta's suggestion, only thing i dont get is how to actually count the blobs using that method, i can get it to pass over all the blocks, but no way to tell when the end of a blob has been reached.
FaCE_1
Profile Blog Joined December 2006
Canada6182 Posts
October 14 2009 03:02 GMT
#15
due in 2 hours.. if it was due in 2 days, i could help
n_n
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
October 14 2009 03:09 GMT
#16
http://pastebin.com/d3e835a75

its been updated. its almost done, can anyone help finish it?
AeTheReal
Profile Joined June 2009
United States108 Posts
October 14 2009 03:22 GMT
#17
Well, that's a major change from when I started looking at it...

As far as I can tell, the previous version of the code did not work because you never modified the value of a cell when you added it to the stack in the while loop. And since you keep on adding more items to the stack which each added more since nothing was being ruled out on subsequent loops, the while loop never ends. Also, you are probably supposed to check your bounds to be "var >= 0" instead of "var > 0" unless you don't need to check the 0 index for some reason.

In your new code your upper bound should be comparing ">=" theGrid.getRows() instead. Same for the .getCols() one.

else if(gridCopy[curr_x][curr_y] == 0){return;}

Use double equal signs for comparisons. Common mistake.

gridCopy[curr_x][curr_y] = 0;

That should go before you make the recursive calls or you'll get the same error.


Hope this helps.
SonuvBob
Profile Blog Joined October 2006
Aiur21550 Posts
Last Edited: 2009-10-14 03:43:16
October 14 2009 03:29 GMT
#18
No idea what this thing is supposed to do, but your counter doesn't increment.

edit: oh, didn't read the whole OP I guess
Administrator
AeTheReal
Profile Joined June 2009
United States108 Posts
October 14 2009 03:33 GMT
#19
I'm pretty sure that's supposed to count the number of blobs. Unfortunately, the code doesn't ever determine whether each location is part of a blob or not.
yenta
Profile Blog Joined April 2006
Poland1142 Posts
October 14 2009 03:35 GMT
#20
On October 14 2009 11:34 tossinYoSalad wrote:
Show nested quote +
On October 14 2009 11:29 yenta wrote:
On October 14 2009 11:16 tossinYoSalad wrote:
On October 14 2009 11:12 yenta wrote:
What are the INPUTs and OUTPUTs of this function supposed to be?


all it does is count the number of blobs and keep track of the recursion depth. numBlobs is incremented immediately after the while loop and recDepth is incremented at the end of the function.

i know its a horrible implementation believe me.


Rewrite it like this:

RECURSIVE CALLER
Initialize count
Initialize array of array with flags (w/e you want)
FOR( 0...x )
FOR( 0..y )
if point @ x,y is unchecked & x.y is a space, call recursive worker
//FOR
//FOR
return w/e

RECURSIVE WORKER ( root, current_x, current_y, pointer to 2D array, ref to count )
base case:
return if out of bounds
return if space you're looking has been marked 'looked at'
recursive case:
count adj spaces by calling self with: ( x-1,y ), ( x+1, y), (x, y+1), (x, y-1) + diagonals if they count.
if adj spaces > 0 & root == true, increment counter //endif
mark current space as read
END


thanks alot, what do you mean by root though? and because the 2d array is a class var i dont need to pass it though do i?

look at this:
http://pastebin.com/m7c4ab47d
Trutacz Practice Discord - https://discord.gg/PWF7Pv
prOxi.swAMi
Profile Blog Joined November 2004
Australia3091 Posts
October 14 2009 03:48 GMT
#21
Wow, that's messy :S needs mass refactoring.
A tip for writing procedurally complex code like that is to employ comment-first coding which allows you to understand exactly what it is you need to do before you even write it. This code was obviously written "as you went along".

Start fresh, write a bunch of pseudocode in comments, then all you should have to do is fill in the logic under the comments.
Oh no
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
October 14 2009 03:53 GMT
#22
On October 14 2009 12:48 prOxi.swAMi wrote:
Wow, that's messy :S needs mass refactoring.
A tip for writing procedurally complex code like that is to employ comment-first coding which allows you to understand exactly what it is you need to do before you even write it. This code was obviously written "as you went along".

Start fresh, write a bunch of pseudocode in comments, then all you should have to do is fill in the logic under the comments.


uhh were you looking at the most recent version? cuz its very simple now lol. and.. this is due in 10 mins so i dont really have time to do it. its logically correct, ive had 4 people look at it and agree, but for some reason its endlessly looping between 4 method calls and.. well idk. ill just submit it as is and hope for the best. oddly enough correctness is NOT a huge part of our project grades.

thanks for help everyone, especially yenta.
SonuvBob
Profile Blog Joined October 2006
Aiur21550 Posts
Last Edited: 2009-10-14 03:59:16
October 14 2009 03:56 GMT
#23
Did you move gridCopy[curr_x][curr_y] = 0; to before the recursive calls?

On October 14 2009 12:53 tossinYoSalad wrote:
oddly enough correctness is NOT a huge part of our project grades.

Yeah, I'd take clean code that doesn't quite work over that mess you started with any day. Adding anything to that would be a nightmare, but fixing the newer version should be easy.
Administrator
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
Last Edited: 2009-10-14 04:00:06
October 14 2009 03:58 GMT
#24
On October 14 2009 12:56 SonuvBob wrote:
Did you move gridCopy[curr_x][curr_y] = 0; to before the recursive calls?


yes i did



edit: haha well thats what i get when i wait till last day to do programming assignments. this is like the 10th class ive taken involving programming and this is the only assignment ive EVER had problems with.
yenta
Profile Blog Joined April 2006
Poland1142 Posts
October 14 2009 04:00 GMT
#25
On October 14 2009 12:35 yenta wrote:
Show nested quote +
On October 14 2009 11:34 tossinYoSalad wrote:
On October 14 2009 11:29 yenta wrote:
On October 14 2009 11:16 tossinYoSalad wrote:
On October 14 2009 11:12 yenta wrote:
What are the INPUTs and OUTPUTs of this function supposed to be?


all it does is count the number of blobs and keep track of the recursion depth. numBlobs is incremented immediately after the while loop and recDepth is incremented at the end of the function.

i know its a horrible implementation believe me.


Rewrite it like this:

RECURSIVE CALLER
Initialize count
Initialize array of array with flags (w/e you want)
FOR( 0...x )
FOR( 0..y )
if point @ x,y is unchecked & x.y is a space, call recursive worker
//FOR
//FOR
return w/e

RECURSIVE WORKER ( root, current_x, current_y, pointer to 2D array, ref to count )
base case:
return if out of bounds
return if space you're looking has been marked 'looked at'
recursive case:
count adj spaces by calling self with: ( x-1,y ), ( x+1, y), (x, y+1), (x, y-1) + diagonals if they count.
if adj spaces > 0 & root == true, increment counter //endif
mark current space as read
END


thanks alot, what do you mean by root though? and because the 2d array is a class var i dont need to pass it though do i?

look at this:
http://pastebin.com/m7c4ab47d


quoting myself incase you missed the solution i posted :p
Trutacz Practice Discord - https://discord.gg/PWF7Pv
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
October 14 2009 04:07 GMT
#26
On October 14 2009 13:00 yenta wrote:
Show nested quote +
On October 14 2009 12:35 yenta wrote:
On October 14 2009 11:34 tossinYoSalad wrote:
On October 14 2009 11:29 yenta wrote:
On October 14 2009 11:16 tossinYoSalad wrote:
On October 14 2009 11:12 yenta wrote:
What are the INPUTs and OUTPUTs of this function supposed to be?


all it does is count the number of blobs and keep track of the recursion depth. numBlobs is incremented immediately after the while loop and recDepth is incremented at the end of the function.

i know its a horrible implementation believe me.


Rewrite it like this:

RECURSIVE CALLER
Initialize count
Initialize array of array with flags (w/e you want)
FOR( 0...x )
FOR( 0..y )
if point @ x,y is unchecked & x.y is a space, call recursive worker
//FOR
//FOR
return w/e

RECURSIVE WORKER ( root, current_x, current_y, pointer to 2D array, ref to count )
base case:
return if out of bounds
return if space you're looking has been marked 'looked at'
recursive case:
count adj spaces by calling self with: ( x-1,y ), ( x+1, y), (x, y+1), (x, y-1) + diagonals if they count.
if adj spaces > 0 & root == true, increment counter //endif
mark current space as read
END


thanks alot, what do you mean by root though? and because the 2d array is a class var i dont need to pass it though do i?

look at this:
http://pastebin.com/m7c4ab47d


quoting myself incase you missed the solution i posted :p



holy shit i didnt see that before lol. thanks man but its too late now. you can see my final solution at http://pastebin.com/d3918f10e.

i modified your solution slightly to simply have every call of processWork mark off an entire blob and then every iteration of the loop in processGrid increment the number of blobs.
ph33r
Profile Joined June 2007
Canada58 Posts
October 14 2009 04:10 GMT
#27
line 13:
you have an assignment instead of condition
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
October 14 2009 04:14 GMT
#28
[image loading]


hey if anyone is curious.. i fixed it, 10 minutes after project was due. sonovbob found the broken code like 10 posts back i just missed it lol. it was the comparison == , and i was using =. fucking stupid c++ compiler should catch that lol.

anyway... thats what it does.
AeTheReal
Profile Joined June 2009
United States108 Posts
October 14 2009 05:16 GMT
#29
On October 14 2009 13:14 tossinYoSalad wrote:
sonovbob found the broken code like 10 posts back i just missed it lol.

... did he now?
Slithe
Profile Blog Joined February 2007
United States985 Posts
October 14 2009 05:19 GMT
#30
The compiler's not going to catch it because it's a legal operation, not an error. When you do an assignment, the assigned variable is the return value.
imDerek
Profile Blog Joined August 2007
United States1944 Posts
Last Edited: 2009-10-14 06:06:30
October 14 2009 06:00 GMT
#31
Least favorite progamers: Leta, Zero, Mind, Shine, free, really <-- newly added
GogoKodo
Profile Blog Joined April 2003
Canada1785 Posts
October 14 2009 06:07 GMT
#32
On October 14 2009 13:14 tossinYoSalad wrote:

hey if anyone is curious.. i fixed it, 10 minutes after project was due. sonovbob found the broken code like 10 posts back i just missed it lol. it was the comparison == , and i was using =. fucking stupid c++ compiler should catch that lol.

anyway... thats what it does.

It's not a compile error so it shouldn't catch that. Doing assignment within a conditional is a pretty normal thing to do.
If you want some help from the compiler I believe there are certain warning flags you can set that will give a warning if you do not parenthesize the assignment within the conditional.

if( something = newSomething)
...
Could be set up to give you a compiler warning which would then go away if it was changed to
if( (something = newSomething) )
...

Can't remember the exact flag you need but I'm sure you can google it easily enough.
twitter: @terrancem
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
Last Edited: 2009-10-14 06:32:55
October 14 2009 06:31 GMT
#33
On October 14 2009 14:16 AeTheReal wrote:
Show nested quote +
On October 14 2009 13:14 tossinYoSalad wrote:
sonovbob found the broken code like 10 posts back i just missed it lol.

... did he now?



yes.. yes.. he did.


as to the assignment within a conditional, yeah i know its a legal operation i was just mad that i didnt catch it lol. I normally don't mess that up so I don't think to check it.

also, when would you need to do an assignment within a conditional? i cant really find a use for that..
SonuvBob
Profile Blog Joined October 2006
Aiur21550 Posts
October 14 2009 06:32 GMT
#34
On October 14 2009 14:16 AeTheReal wrote:
Show nested quote +
On October 14 2009 13:14 tossinYoSalad wrote:
sonovbob found the broken code like 10 posts back i just missed it lol.

... did he now?

I must've used my admin powers to post it as someone else.
Administrator
EtherealDeath
Profile Blog Joined July 2007
United States8366 Posts
October 14 2009 06:40 GMT
#35
On October 14 2009 13:14 tossinYoSalad wrote:
[image loading]


hey if anyone is curious.. i fixed it, 10 minutes after project was due. sonovbob found the broken code like 10 posts back i just missed it lol. it was the comparison == , and i was using =. fucking stupid c++ compiler should catch that lol.

anyway... thats what it does.



Recursion depth 534 o.O
Didn't read the code, though that seems like a lot of recursion. Prolly would've done it by recursively calling hasBlobProperty() and having the outer layer go through every array position that hasn't already been marked as having a part of a blob there, and the second layer would keep track of the # of blobs. But apparently your method works so it's all good =)
Amnesia
Profile Blog Joined September 2009
United States3818 Posts
October 14 2009 06:41 GMT
#36
Jesus christ, you guys are so awesome. I wish I knew a programming language. Just looking at the way you talk makes my head hurt.

Is C++ hard to learn?
EtherealDeath
Profile Blog Joined July 2007
United States8366 Posts
Last Edited: 2009-10-14 06:45:47
October 14 2009 06:43 GMT
#37
nah C++ is pretty easy, although nowadays I suggest you learn Java or C#

EDIT: Although, if I recall correctly C# can execute up to 40 times slower than C++, and the JVM means Java is slower as well (but you would learn the details yourself in a Java course). Of course, efficiency usually won't matter too much... though I think most games are not made with Java/C# (WoW for instance is written in C++), but you would use a lot of C# and Java in other programming jobs.
GogoKodo
Profile Blog Joined April 2003
Canada1785 Posts
October 14 2009 06:52 GMT
#38
On October 14 2009 15:31 tossinYoSalad wrote:
Show nested quote +
On October 14 2009 14:16 AeTheReal wrote:
On October 14 2009 13:14 tossinYoSalad wrote:
sonovbob found the broken code like 10 posts back i just missed it lol.

... did he now?



yes.. yes.. he did.


as to the assignment within a conditional, yeah i know its a legal operation i was just mad that i didnt catch it lol. I normally don't mess that up so I don't think to check it.

also, when would you need to do an assignment within a conditional? i cant really find a use for that..


I don't think it's ever a necessity (could be wrong), it's just a nice convenience for a lot of things.
twitter: @terrancem
Disregard
Profile Blog Joined March 2007
China10252 Posts
Last Edited: 2009-10-14 07:00:27
October 14 2009 06:59 GMT
#39
Damn, this looks a lot harder than Java. Does C++ use the same operators?
"If I had to take a drug in order to be free, I'm screwed. Freedom exists in the mind, otherwise it doesn't exist."
Slithe
Profile Blog Joined February 2007
United States985 Posts
October 14 2009 07:14 GMT
#40
The issue with c++ is that there are a lot of nuances to it that gives it a steeper learning curve. As a result, one is a lot more error-prone when writing c++ code.

Regarding the assignment inside a conditional, here's random example code where it might be used:

char[] str = "Hello TeamLiquid!"
char c;
for (int i = 0; (c=str[i]) != 0; i++) {
printf("Letter: %c", c);
}

From a stylistic point of view, I don't think it's usually a particularly good idea, but it would be inconsistent to treat the assignment differently just because it was placed inside a conditional statement.
PaiNt)
Profile Joined June 2009
United States38 Posts
October 14 2009 07:16 GMT
#41
compiling with -Wall may have brought up that error.
something like g++ -Wall project.cpp
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
Last Edited: 2009-10-14 19:14:41
October 14 2009 19:10 GMT
#42
On October 14 2009 16:14 Slithe wrote:
The issue with c++ is that there are a lot of nuances to it that gives it a steeper learning curve. As a result, one is a lot more error-prone when writing c++ code.

Regarding the assignment inside a conditional, here's random example code where it might be used:

char[] str = "Hello TeamLiquid!"
char c;
for (int i = 0; (c=str[i]) != 0; i++) {
printf("Letter: %c", c);
}

From a stylistic point of view, I don't think it's usually a particularly good idea, but it would be inconsistent to treat the assignment differently just because it was placed inside a conditional statement.


Huh that does make a lot of sense actually lol. I'm just used to java where if the if() statement doesn't resolve to a boolean it doesn't compile. C++ is nice and I like the fact that you have more freedom and it compiles directly to machine language and all, but some things about it just frustrate me. Like the fact that you can't declare an array without having a definite size for it ( yes I tried using extern.)

Also thanks a ton to everyone who helped me out. You guys rock .

oh and Sonovbob didnt catch the error. Sorry aethereal. He found another error though .
ph33r
Profile Joined June 2007
Canada58 Posts
October 14 2009 20:08 GMT
#43
On October 15 2009 04:10 tossinYoSalad wrote:
Show nested quote +
On October 14 2009 16:14 Slithe wrote:
The issue with c++ is that there are a lot of nuances to it that gives it a steeper learning curve. As a result, one is a lot more error-prone when writing c++ code.

Regarding the assignment inside a conditional, here's random example code where it might be used:

char[] str = "Hello TeamLiquid!"
char c;
for (int i = 0; (c=str[i]) != 0; i++) {
printf("Letter: %c", c);
}

From a stylistic point of view, I don't think it's usually a particularly good idea, but it would be inconsistent to treat the assignment differently just because it was placed inside a conditional statement.


Huh that does make a lot of sense actually lol. I'm just used to java where if the if() statement doesn't resolve to a boolean it doesn't compile. C++ is nice and I like the fact that you have more freedom and it compiles directly to machine language and all, but some things about it just frustrate me. Like the fact that you can't declare an array without having a definite size for it ( yes I tried using extern.)

Also thanks a ton to everyone who helped me out. You guys rock .

oh and Sonovbob didnt catch the error. Sorry aethereal. He found another error though .


You can use vectors if you want to implement dynamic arrays, or use pointers, like:

int *ptr;
ptr = new int[5];
...
int *ptr2 = new int[10];
for ( ... ) ptr2[i] = ptr[i];
delete[] ptr;
b3h47pte
Profile Blog Joined May 2007
United States1317 Posts
October 14 2009 20:32 GMT
#44
On October 14 2009 15:43 EtherealDeath wrote:
nah C++ is pretty easy, although nowadays I suggest you learn Java or C#

EDIT: Although, if I recall correctly C# can execute up to 40 times slower than C++, and the JVM means Java is slower as well (but you would learn the details yourself in a Java course). Of course, efficiency usually won't matter too much... though I think most games are not made with Java/C# (WoW for instance is written in C++), but you would use a lot of C# and Java in other programming jobs.


if you want to do game programming i believe you should learn C++ but you can also do some C#/XNA stuff if you're more inclined to do so that way..

However I do believe more software jobs (outside of games) use C#/Java for newer stuff. At the place where i interned at, their old utilities were written in VB6 with the newer ones using C#.
tossinYoSalad
Profile Blog Joined May 2009
United States215 Posts
October 14 2009 21:25 GMT
#45
On October 15 2009 05:08 ph33r wrote:
Show nested quote +
On October 15 2009 04:10 tossinYoSalad wrote:
On October 14 2009 16:14 Slithe wrote:
The issue with c++ is that there are a lot of nuances to it that gives it a steeper learning curve. As a result, one is a lot more error-prone when writing c++ code.

Regarding the assignment inside a conditional, here's random example code where it might be used:

char[] str = "Hello TeamLiquid!"
char c;
for (int i = 0; (c=str[i]) != 0; i++) {
printf("Letter: %c", c);
}

From a stylistic point of view, I don't think it's usually a particularly good idea, but it would be inconsistent to treat the assignment differently just because it was placed inside a conditional statement.


Huh that does make a lot of sense actually lol. I'm just used to java where if the if() statement doesn't resolve to a boolean it doesn't compile. C++ is nice and I like the fact that you have more freedom and it compiles directly to machine language and all, but some things about it just frustrate me. Like the fact that you can't declare an array without having a definite size for it ( yes I tried using extern.)

Also thanks a ton to everyone who helped me out. You guys rock .

oh and Sonovbob didnt catch the error. Sorry aethereal. He found another error though .


You can use vectors if you want to implement dynamic arrays, or use pointers, like:

int *ptr;
ptr = new int[5];
...
int *ptr2 = new int[10];
for ( ... ) ptr2[i] = ptr[i];
delete[] ptr;



Yeah I could have done that but it was unnecessary as it just required a two-dim array of fixed size. It created a problem because I wanted to have all references to the size of the array come from a single method, and you cannot do this upon creating the array (apparently). It wasn't a huge issue but it just irked me because I couldn't follow basic good programming principles.
Normal
Please log in or register to reply.
Live Events Refresh
Next event in 25m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 400
IndyStarCraft 165
JuggernautJason123
StarCraft: Brood War
Britney 20427
Calm 2808
Shuttle 425
Mini 393
EffOrt 228
ggaemo 104
Dewaltoss 103
Oya187 41
Dota 2
Gorgc5599
qojqva2742
420jenkins14
LuMiX1
Counter-Strike
fl0m10733
byalli535
chrisJcsgo42
Super Smash Bros
hungrybox187
Heroes of the Storm
Khaldor603
Liquid`Hasu501
Other Games
Grubby1119
Beastyqt669
ArmadaUGS124
XaKoH 63
OptimusSC21
Organizations
Other Games
gamesdonequick1212
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• HeavenSC 57
• Adnapsc2 14
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV467
League of Legends
• Nemesis2764
Other Games
• imaqtpie2012
• Shiphtur702
Upcoming Events
IPSL
25m
Sziky vs JDConan
BSL 21
25m
Tech vs Cross
Bonyth vs eOnzErG
Replay Cast
13h 25m
Wardi Open
16h 25m
Monday Night Weeklies
21h 25m
Sparkling Tuna Cup
1d 14h
Replay Cast
3 days
The PondCast
3 days
CranKy Ducklings
5 days
SC Evo League
5 days
[ Show More ]
BSL 21
6 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

Acropolis #4 - TS3
RSL Revival: Season 3
Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
Slon Tour Season 2
WardiTV 2025
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22

Upcoming

CSL 2025 WINTER (S19)
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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.