• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:32
CEST 08:32
KST 15:32
  • 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
Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun12[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists22[ASL21] Ro16 Preview Pt1: Fresh Flow9
Community News
RSL Revival: Season 5 - Qualifiers and Main Event4Code S Season 1 (2026) - RO12 Results02026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced92026 GSL Tour plans announced15
StarCraft 2
General
Code S Season 1 (2026) - RO12 Results Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun Team Liquid Map Contest #22 - The Finalists Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool MaNa leaves Team Liquid
Tourneys
RSL Revival: Season 5 - Qualifiers and Main Event GSL Code S Season 1 (2026) SC2 INu's Battles#15 <BO.9 2Matches> WardiTV Spring Cup SEL Masters #6 - Solar vs Classic (SC: Evo)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base Mutation # 521 Memorable Boss
Brood War
General
Pros React To: Leta vs Tulbo (ASL S21, Ro.8) [BSL22] RO16 Group A - Sunday 21:00 CEST [BSL22] RO16 Group B - Saturday 21:00 CEST RepMastered™: replay sharing and analyzer site BW General Discussion
Tourneys
[BSL22] RO16 Group Stage - 02 - 10 May Escore Tournament StarCraft Season 2 [Megathread] Daily Proleagues [ASL21] Ro8 Day 2
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Daigo vs Menard Best of 10 Stormgate/Frost Giant Megathread Nintendo Switch Thread Dawn of War IV Diablo IV
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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 TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread Russo-Ukrainian War Thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Sexual Health Of Gamers
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1576 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
Poland17741 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
Poland17741 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 2h 28m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech138
StarCraft: Brood War
firebathero 336
Shine 304
PianO 272
Backho 148
Aegong 89
ZergMaN 16
scan(afreeca) 11
JulyZerg 6
Dota 2
NeuroSwarm198
League of Legends
JimRising 715
Counter-Strike
Stewie2K1242
Other Games
summit1g6940
WinterStarcraft658
C9.Mang0510
monkeys_forever360
Sick154
ToD24
Organizations
Other Games
gamesdonequick791
Dota 2
PGL Dota 2 - Main Stream83
StarCraft: Brood War
UltimateBattle 53
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 13 non-featured ]
StarCraft 2
• Response 14
• Sammyuel 12
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt520
Upcoming Events
Replay Cast
2h 28m
RSL Revival
3h 28m
Classic vs GgMaChine
Rogue vs Maru
WardiTV Invitational
4h 28m
Percival vs Shameless
ByuN vs YoungYakov
SC Evo League
7h 28m
IPSL
9h 28m
Ret vs Art_Of_Turtle
Radley vs TBD
BSL
12h 28m
Replay Cast
17h 28m
RSL Revival
1d 3h
herO vs TriGGeR
NightMare vs Solar
uThermal 2v2 Circuit
1d 7h
BSL
1d 12h
[ Show More ]
IPSL
1d 12h
eOnzErG vs TBD
G5 vs Nesh
Patches Events
1d 17h
Replay Cast
2 days
Wardi Open
2 days
Afreeca Starleague
2 days
Jaedong vs Light
Monday Night Weeklies
2 days
Replay Cast
2 days
Sparkling Tuna Cup
3 days
Afreeca Starleague
3 days
Snow vs Flash
WardiTV Invitational
3 days
GSL
4 days
Classic vs Cure
Maru vs Rogue
GSL
5 days
SHIN vs Zoun
ByuN vs herO
OSC
5 days
Replay Cast
5 days
Escore
6 days
The PondCast
6 days
WardiTV Invitational
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Escore Tournament S2: W5
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
KK 2v2 League Season 1
Acropolis #4
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 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.