• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 14:30
CET 20:30
KST 04:30
  • 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
SC2 All-Star Invitational: Tournament Preview2RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2
Community News
Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)15Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7[BSL21] Non-Korean Championship - Starts Jan 103SC2 All-Star Invitational: Jan 17-1834
StarCraft 2
General
Stellar Fest "01" Jersey Charity Auction SC2 All-Star Invitational: Tournament Preview Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets When will we find out if there are more tournament SC2 Spotted on the EWC 2026 list?
Tourneys
SC2 All-Star Invitational: Jan 17-18 OSC Season 13 World Championship SC2 AI Tournament 2026 Sparkling Tuna Cup - Weekly Open Tournament $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes
Brood War
General
[ASL21] Potential Map Candidates How Rain Became ProGamer in Just 3 Months BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ A cwal.gg Extension - Easily keep track of anyone
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] Grand Finals - Sunday 21:00 CET [BSL21] Non-Korean Championship - Starts Jan 10
Strategy
Soma's 9 hatch build from ASL Game 2 Simple Questions, Simple Answers Game Theory for Starcraft Current Meta
Other Games
General Games
Beyond All Reason Awesome Games Done Quick 2026! Nintendo Switch Thread Mechabellum Stormgate/Frost Giant Megathread
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine Trading/Investing Thread
Fan Clubs
Innova Crysta on Hire
Media & Entertainment
Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
My 2025 Magic: The Gathering…
DARKING
Physical Exercise (HIIT) Bef…
TrAiDoS
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1800 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
Poland17606 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
Poland17606 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
Next event in 6h 45m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 625
JuggernautJason103
UpATreeSC 96
EmSc Tv 33
MindelVK 18
IndyStarCraft 9
StarCraft: Brood War
Britney 23768
Shuttle 374
firebathero 143
Dewaltoss 133
Hyun 70
Mong 53
HiyA 13
Bale 12
Dota 2
420jenkins423
BananaSlamJamma204
League of Legends
C9.Mang0143
Counter-Strike
fl0m2143
byalli1061
Fnx 761
adren_tv80
Other Games
Grubby2660
Liquid`RaSZi2056
FrodaN1208
Beastyqt938
Harstem324
Liquid`Hasu266
Mlord155
ToD151
QueenE141
KnowMe127
mouzStarbuck35
Mew2King19
Organizations
Other Games
gamesdonequick2289
StarCraft 2
EmSc Tv 33
EmSc2Tv 33
Other Games
BasetradeTV17
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• StrangeGG 74
• maralekos11
• Migwel
• AfreecaTV YouTube
• intothetv
• sooper7s
• Kozan
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• FirePhoenix21
• HerbMon 20
• 80smullet 19
• Azhi_Dahaki4
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• TFBlade1821
• Shiphtur547
Other Games
• imaqtpie1202
Upcoming Events
All-Star Invitational
6h 45m
INnoVation vs soO
Serral vs herO
Cure vs Solar
sOs vs Scarlett
Classic vs Clem
Reynor vs Maru
uThermal 2v2 Circuit
16h 30m
AI Arena Tournament
1d
All-Star Invitational
1d 6h
MMA vs DongRaeGu
Rogue vs Oliveira
Sparkling Tuna Cup
1d 14h
OSC
1d 16h
Replay Cast
2 days
Wardi Open
2 days
Monday Night Weeklies
2 days
The PondCast
4 days
[ Show More ]
Replay Cast
6 days
Big Brain Bouts
6 days
Serral vs TBD
Liquipedia Results

Completed

Proleague 2026-01-14
Big Gabe Cup #3
NA Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
OSC Championship Season 13
Underdog Cup #3
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025

Upcoming

Escore Tournament S1: W5
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
SC2 All-Star Inv. 2025
Nations Cup 2026
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 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.