• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 15:45
CEST 21:45
KST 04:45
  • 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
[ASL22] Ro16 Preview: Rough Waters10[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915Serral wins Maestros of the Game 244
Community News
StarCraft open world shooter announced at BlizzCon28Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism10Official StarCraft website teases new content ahead of BlizzCon?157Stellar Fest TWO the Moon (Dec 16-20)9Weekly Cups (August 24-30): Patches' balance mod takes over3
StarCraft 2
General
StarCraft open world shooter announced at BlizzCon Balance hotfix patch 5.0.16b (July 16) Team Liquid Map Contest #22: Results and Winners Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism SC4ALL: II Winner will earn a spot at HSC 30!
Tourneys
RSL goes to London! 2026 Offline Finals Nov 21-22 KSL Week #92 IntoTheTV X SOOP SC2 League : Weekly & Monthly 2026 GSTL Announcement Sparkling Tuna Cup - Weekly Open Tournament
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 542 The Ascended Mutation # 541 Binary Choice The PondCast: SC2 News & Results Mutation # 540 Dodge This
Brood War
General
Official StarCraft website teases new content ahead of BlizzCon? Broodwar Prediction Market BGH Auto Balance -> http://bghmmr.eu/ Practice Partners (Official) [D] Brainstorming a balance patch for Brood war
Tourneys
[ASL22] Ro16 Group A [ASL22] Ro16 Group B Escore Tournament - Season 3 Small VOD Thread 2.0
Strategy
Replay Review Process - What do you do? Simple Questions, Simple Answers Odyssey Mineral Stack Saturation Game Theory for Starcraft
Other Games
General Games
Diablo IV Nintendo Switch Thread EVE Corporation [Maplestory Hardcore] Let's Play~!! General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread UK Politics Mega-thread Things Aren’t Peaceful in Palestine Trading/Investing Thread Russo-Ukrainian War Thread
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
Diablo Animated Series on Netflix Movie Discussion!
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Virtual Romance, Real-Life C…
TrAiDoS
Regacy Esports:Our Goa…
regacyesports
Dreaming of BW patches (mod…
c3rberUs
LOCKPICKING NOOB
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7283 users

The Big Programming Thread - Page 553

Forum Index > General Forum
Post a Reply
Prev 1 551 552 553 554 555 1032 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.
Animzor
Profile Joined March 2011
Sweden2154 Posts
Last Edited: 2014-12-01 23:30:13
December 01 2014 23:27 GMT
#11041
Thanks for the help. Here's another question while I'm at it. This is basically just a question about making my code better:

+ Show Spoiler +
do{
okInput = true;
try{
System.out.println("Skriv in ett datum: ");
datum = keyboard.nextLine();
if(datum.isEmpty()){
throw new IllegalArgumentException();
}

} catch(IllegalArgumentException e){
System.out.println("raden är tom");
okInput = false;
}
} while(!okInput);

do{
okInput = true;
try{
System.out.println("Ange en beskrivning: ");
beskrivning = keyboard.nextLine();
if(beskrivning.isEmpty()){
throw new IllegalArgumentException();
}

} catch(IllegalArgumentException e){
System.out.println("raden är tom");
okInput = false;
}
}while(!okInput);


I'm using do/while loops and try/catch blocks to add dates and descriptions to an object, but I get the feeling this is a stupid way to go about this since I'm reusing the same code over and over again. This is just a small part of the method, there's actually 6 instances where I use the same do/while and try/catch to do basically the same thing, adding things to an object. So I'm assuming there's a better way. I've thought about making the try/catch blocks into a separate method so I can just run the method on each field that I want to check for exceptions. The problem is that I can't find a way to return to the beginning of the loop if the exception is caught in another method, the program just keeps running without asking the user for correct input.

So the question is, how do I set the boolean okInput to false if the exception is being caught by another method?
LaNague
Profile Blog Joined April 2010
Germany9118 Posts
Last Edited: 2014-12-01 23:31:15
December 01 2014 23:28 GMT
#11042
well ok so i made q quick reply for a quick homework question.



Array...DEPENDS on what the application would be used for, are the users sorted or not?
he is allready using an array for his references (also called pointers by me previously), so what is the harm in using a second one where you store the corresponding integer values. Its a work around because i dont think java lets you have a 2 dim array with two different types.
He allready has the users in an array, so the second array only doubles delete and insert actions and laos i dont think he has a sorted array, so the costs are not high anyways.
And memory is no problem as well, because the array is the cheapest way to store the data, all custom classes will also need space for pointers.

so pointer, reference, meep, mooop.

If you make a custom class to hold those two attributes, why would you NOT make them public, there is nothing you do with them, you only want to store them. What would be the point of making a get and a set function, they dont have to validate anything.
If you really care about java, you could also look up if there is some struct interface or object that you can inherit from, probably not the scope of the homework.




Also btw, i took the one array as a given, so that excluded all those collection classes :p
LaNague
Profile Blog Joined April 2010
Germany9118 Posts
Last Edited: 2014-12-01 23:51:07
December 01 2014 23:39 GMT
#11043
On December 02 2014 08:27 Animzor wrote:
Thanks for the help. Here's another question while I'm at it. This is basically just a question about making my code better:

+ Show Spoiler +
do{
okInput = true;
try{
System.out.println("Skriv in ett datum: ");
datum = keyboard.nextLine();
if(datum.isEmpty()){
throw new IllegalArgumentException();
}

} catch(IllegalArgumentException e){
System.out.println("raden är tom");
okInput = false;
}
} while(!okInput);

do{
okInput = true;
try{
System.out.println("Ange en beskrivning: ");
beskrivning = keyboard.nextLine();
if(beskrivning.isEmpty()){
throw new IllegalArgumentException();
}

} catch(IllegalArgumentException e){
System.out.println("raden är tom");
okInput = false;
}
}while(!okInput);


I'm using do/while loops and try/catch blocks to add dates and descriptions to an object, but I get the feeling this is a stupid way to go about this since I'm reusing the same code over and over again. This is just a small part of the method, there's actually 6 instances where I use the same do/while and try/catch to do basically the same thing, adding things to an object. So I'm assuming there's a better way. I've thought about making the try/catch blocks into a separate method so I can just run the method on each field that I want to check for exceptions. The problem is that I can't find a way to return to the beginning of the loop if the exception is caught in another method, the program just keeps running without asking the user for correct input.

So the question is, how do I set the boolean okInput to false if the exception is being caught by another method?




Im not sure what your problem is exactly, but you can make a new mthod that returns boolean, for example false if its empty and true if its not empty. Is the string a class attribute or did you use that as the function return vlaue allready?


A method can also hand down exceptions to the calling code.
Animzor
Profile Joined March 2011
Sweden2154 Posts
Last Edited: 2014-12-01 23:55:20
December 01 2014 23:54 GMT
#11044
On December 02 2014 08:39 LaNague wrote:
Show nested quote +
On December 02 2014 08:27 Animzor wrote:
Thanks for the help. Here's another question while I'm at it. This is basically just a question about making my code better:

+ Show Spoiler +
do{
okInput = true;
try{
System.out.println("Skriv in ett datum: ");
datum = keyboard.nextLine();
if(datum.isEmpty()){
throw new IllegalArgumentException();
}

} catch(IllegalArgumentException e){
System.out.println("raden är tom");
okInput = false;
}
} while(!okInput);

do{
okInput = true;
try{
System.out.println("Ange en beskrivning: ");
beskrivning = keyboard.nextLine();
if(beskrivning.isEmpty()){
throw new IllegalArgumentException();
}

} catch(IllegalArgumentException e){
System.out.println("raden är tom");
okInput = false;
}
}while(!okInput);


I'm using do/while loops and try/catch blocks to add dates and descriptions to an object, but I get the feeling this is a stupid way to go about this since I'm reusing the same code over and over again. This is just a small part of the method, there's actually 6 instances where I use the same do/while and try/catch to do basically the same thing, adding things to an object. So I'm assuming there's a better way. I've thought about making the try/catch blocks into a separate method so I can just run the method on each field that I want to check for exceptions. The problem is that I can't find a way to return to the beginning of the loop if the exception is caught in another method, the program just keeps running without asking the user for correct input.

So the question is, how do I set the boolean okInput to false if the exception is being caught by another method?




Im not sure what your problem is exactly, but you can make a new mthod that returns boolean, for example false if its empty and true if its not empty. Is the string a class attribute or did you use that as the function return vlaue allready?


A method can also hand down exceptions to the calling code.


The problem is that every time I get an exception for an empty string I want the program to return to the top of the loop and try again AND I want to have several prompts to the user to input different information in the same do/while and try/catch block.
LaNague
Profile Blog Joined April 2010
Germany9118 Posts
Last Edited: 2014-12-02 00:10:27
December 02 2014 00:07 GMT
#11045
you can print the message where you tell the user what to do right after you print the error message and then you dont need 6 different loops, only 6 different error handlers.



I also dont like the use of exceptions for things that are trivial such as this, but thats a matter of opinion.
Animzor
Profile Joined March 2011
Sweden2154 Posts
December 02 2014 00:31 GMT
#11046
Now that you mention it, the exceptions are really silly in this case.
Abductedonut
Profile Blog Joined December 2010
United States324 Posts
Last Edited: 2014-12-02 00:57:54
December 02 2014 00:56 GMT
#11047
On December 02 2014 09:31 Animzor wrote:
Now that you mention it, the exceptions are really silly in this case.


I can't really tell what your code is trying to do, but maybe this might help:


boolean detailesComplete = false;

do{
detailsComplete = getCompleteObjectDetails();
}while(!detailsComplete)

public boolean getCompleteObjectDetails()
{
try
{
System.out.println("Skriv in ett datum: ");
datum = getUserInput();

System.out.println("Ange en beskrivning: ");
beskrivning = getUserInput();

//i have no clue what you're going to do with all these variables... but if your code reaches this point that
//means that you've successfully gotten input without someone putting in an empty line
return true;
}
catch(IllegalArgumentException e)
{
System.out.println("Empty Line");
return false;
}
}

public string getUserInput() throws IllegalArgumentException
{
string ret = keyboard.nextLine();

if(ret.isEmpty())
throw IllegalArgumentException;
else
return ret;
}


Totally unverified code, i just wrote this in vim without compiling or anything but hopefully this gives you some ideas.

*edit* I really don't like the detailesVerified portion of the code. In general, you should call getObjectDetails() and have it return object details instead of a boolean, then pass it in to another function verified those details to make sure it's legit, then returns a boolean. Your while loop should then exit based on that condition. But this was just stuff I came up with without really thinking about it.
Cynry
Profile Blog Joined August 2010
810 Posts
Last Edited: 2014-12-02 18:30:56
December 02 2014 18:18 GMT
#11048
Ok this is driving me crazy. I got this list I'm supposed to display (still working on the ls utility), and the first element is .: when using the -R option, to display which directory will be displayed next. All good, I know it's in the list.
But I also got this function to remove hidden files/directories when there is no -a option. This is ok too.

Now my issue : I want said function to not remove the first node, the one with .:, because reasons.
Here's the function :
t_list          *ft_rem_hidden(t_list **output)
{
t_list *cursor;

cursor = *output;
while (cursor)
{
ft_putnbr(ft_strnequ((char const *)cursor->content, ".:", 2));
ft_putendl(cursor->content);
if (ft_strnequ((char const *)cursor->content, ".:", 2) == 0
&& ft_strnequ((char const *)cursor->content, ".", 1)
&& ft_strnequ((char const *)cursor->content, "./", 2) == 0)
ft_lstfreeone(output, cursor);
else
cursor = cursor->next;
}
return (*output);
}


The ft_putendl and ft_putnbr are just to check the value returned by ft_strnequ, and the value, as expected, is 1 only for the .: node. I checked the list content before the while loop, there's a .: at first place, as expected. I checked after the while loop, aaaaaand it's not there anymore.
So, I checked if the .: node was freed by checking the if, which it shouldn't because of the strnequ return value, and it's apparently not, as expected.
So where the hell is my .: node ?

Edit :
I double checked everything to make sure, and I really can't make sense of that.
So, my little node goes throught these lines of code, kinda :
t_list          *ft_rem_hidden(t_list **output)
{
t_list *cursor;

cursor = *output;
while (cursor)
{
cursor = cursor->next;
}
return (*output);
}

And it's there before the while, but not after. Ok.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
December 02 2014 20:54 GMT
#11049
is that a list of lists, or a pointer to a list?
There is no one like you in the universe.
Cynry
Profile Blog Joined August 2010
810 Posts
December 02 2014 21:27 GMT
#11050
It's a pointer to a list. Should be noted that I "cleaned" up the code a little bit, by saving the cursor->next position to a tmp before freeing it, so there is no chance of undefined behaviour. Doesn't change anything to my problem, but thought it was worth mentionning...
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2014-12-02 23:49:33
December 02 2014 23:48 GMT
#11051
sorry, not a list, i meant pointer to an array. you don't have that. you have a linked list node which has different semantics.

your input is a pointer to a pointer to the first element of a linked list. if you set it up improperly such that it's not a pointer, but an address, more specifically the address to the pointer to the first node, when you dereference the pointer you don't get a copy of the pointer but the actual pointer. so when you iterate through your linked list, you're changing the value of the pointer to your linked list. so you're killing your linked list with that call.
There is no one like you in the universe.
Cynry
Profile Blog Joined August 2010
810 Posts
December 03 2014 00:00 GMT
#11052
Uuuuuh, not sure I understand that. A pointer not being equal to an adress is new to me already ^^

So, what I understood is :
let's say the main calls rem_hidden. If in the main I initialize *ouput and call rem_hidden(&output), I fall into the category you described ? And what I should be doing is initializing **output in my main and simply call rem_hidden(output) ?
Manit0u
Profile Blog Joined August 2004
Poland17843 Posts
December 03 2014 00:36 GMT
#11053
http://stackoverflow.com/questions/1736146/why-is-exception-handling-bad
Time is precious. Waste it wisely.
Cynry
Profile Blog Joined August 2010
810 Posts
December 03 2014 00:40 GMT
#11054
I created a git repo with the whole source for my ls, in case someone wants to take a look.
There.
Khalum
Profile Joined September 2010
Austria831 Posts
Last Edited: 2014-12-03 02:45:45
December 03 2014 02:43 GMT
#11055
On December 03 2014 09:36 Manit0u wrote:
http://stackoverflow.com/questions/1736146/why-is-exception-handling-bad

That's ridiculous.

void Frob()
{
m_FrobManager.HandleFrob(new FrobObject());
m_NumberOfFrobs++;
}


Wow, I'm a genius.



I'd also like to contribute my favourite stackoverflow topic: http://stackoverflow.com/questions/22780466/why-cant-my-program-compile-under-windows-7-in-french
Manit0u
Profile Blog Joined August 2004
Poland17843 Posts
December 03 2014 10:26 GMT
#11056
http://www.gotw.ca/gotw/005.htm

C++ and why I'm happy I don't have to code in it
Time is precious. Waste it wisely.
ZenithM
Profile Joined February 2011
France15952 Posts
Last Edited: 2014-12-03 10:59:38
December 03 2014 10:58 GMT
#11057
On December 03 2014 11:43 Khalum wrote:
I'd also like to contribute my favourite stackoverflow topic: http://stackoverflow.com/questions/22780466/why-cant-my-program-compile-under-windows-7-in-french

Edit: Ok my bad, good thread indeed :D
Isualin
Profile Joined March 2011
Germany1903 Posts
December 03 2014 11:47 GMT
#11058
On December 03 2014 19:58 ZenithM wrote:
Show nested quote +
On December 03 2014 11:43 Khalum wrote:
I'd also like to contribute my favourite stackoverflow topic: http://stackoverflow.com/questions/22780466/why-cant-my-program-compile-under-windows-7-in-french

Edit: Ok my bad, good thread indeed :D

I got fooled for a second too :D
| INnoVation | The literal god TY | ByuNjwa | LRSL when? |
Khalum
Profile Joined September 2010
Austria831 Posts
December 03 2014 12:16 GMT
#11059
On December 03 2014 19:26 Manit0u wrote:
http://www.gotw.ca/gotw/005.htm

C++ and why I'm happy I don't have to code in it


What a strange thing to say. I actually quite like the fact that C++ allows you to shoot yourself in the foot and the face at the same time if you don't know what you're doing; yet when you improve in skill it's very satisfying. Unlike Java.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
December 03 2014 14:43 GMT
#11060
--- Nuked ---
Prev 1 551 552 553 554 555 1032 Next
Please log in or register to reply.
Live Events Refresh
AI Arena Tournament
17:00
Swiss - Round 1
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 837
Tasteless 517
JimRising 516
CosmosSc2 63
StarCraft: Brood War
Britney 19995
Calm 2909
Artosis 697
Shuttle 566
Dewaltoss 108
HiyA 83
Mong 46
Hm[arnc] 18
Noble 6
Dota 2
qojqva2962
420jenkins335
monkeys_forever129
canceldota41
Counter-Strike
fl0m3249
Fnx 743
Super Smash Bros
Chillindude18
Heroes of the Storm
Liquid`Hasu1292
Trikslyr101
Other Games
Grubby7387
summit1g4536
B2W.Neo1414
Mlord436
XaKoH 166
QueenE43
Organizations
Heroes of the Storm
Heroes of the Storm3566
Other Games
EGCTV1555
StarCraft 2
StarCraft1503
StarCraft: Brood War
Afreeca ASL 568
Other Games
BasetradeTV225
angryscii39
[ Show 17 non-featured ]
StarCraft 2
• Hupsaiya 98
• EnkiAlexander 55
• printf 36
• Adnapsc2 7
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• Airneanach24
• FirePhoenix12
• Pr0nogo 6
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Other Games
• imaqtpie832
• Shiphtur173
Upcoming Events
OSC
45m
Sparkling Tuna Cup
14h 15m
WardiTV Invitational
15h 15m
ByuN vs Percival
Cure vs Classic
Shopify Rebellion Sundays
19h 15m
Spirit vs Mixu
Clem vs TBD
RSL Revival
20h 15m
Serral vs Rogue
BlizzCon
22h 45m
IdrA vs MC
Replay Cast
1d 4h
Afreeca Starleague
1d 14h
Light vs JyJ
Soulkey vs hero
WardiTV Weekly
1d 15h
Monday Night Weeklies
1d 20h
[ Show More ]
Afreeca Starleague
2 days
Snow vs Shinee
Shine vs EffOrt
GSL
2 days
PiGosaur Cup
3 days
The PondCast
3 days
Kung Fu Cup
3 days
Replay Cast
4 days
KCM Race Survival
4 days
IntoTheTV X SOOP
4 days
Replay Cast
5 days
IntoTheTV X SOOP
5 days
Replay Cast
6 days
GSL
6 days
Liquipedia Results

Completed

Acropolis #5 - TRS
PiG Sty Festival 8.0
Big Dog Cup 2026 Div 1

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
Acropolis #5
RSL Revival: Season 6
Calamity Invitational
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Blizzard Classic Cup 2026
Acropolis #5 - GSA
Acropolis #5 - GSB
Acropolis #5 - GSC
SC4ALL II: Brood War
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
Blizzard Classic Cup 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
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 © 2026 TLnet. All Rights Reserved.