• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:48
CEST 03:48
KST 10:48
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
ZeroSpace Early Access is Now Live!12Weekly Cups (July 13-19): Terran & Protoss rise; Zerg falters2Balance hotfix patch 5.0.16b (July 16)83Reynor: GSL Loss Wasn't About Preparation Format16[IPSL] Spring 2026 Grand Finals - This Weekend!18
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) Weekly Cups (July 13-19): Terran & Protoss rise; Zerg falters How would you feel about frequent/monthly balance patches for SC2? Clem: "I don't have that much hope in Blizzard" [D] Wireframe Casting Removed
Tourneys
RSL Revival: Season 6 - Qualifiers and Main Event Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026 GSL CK #5 Race War HomeStory Cup 29
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
Mutation # 535 Assembly of Vengeance The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion HORROR STARCRAFT MOVIE How Famous was FlaSh before his Debut? screpdb: new Starcraft reporting tool
Tourneys
[Megathread] Daily Proleagues [IPSL] Spring 2026 Grand Finals - This Weekend! Escore Tournament - Season 3 Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers PvT advise for noobs Fighting Spirit mining rates Creating a full chart of Zerg builds
Other Games
General Games
ZeroSpace Early Access is Now Live! Path of Exile General RTS Discussion Thread ZeroSpace at Steam NextFest - Last free demo Nintendo Switch Thread
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Artificial Intelligence Thread Russo-Ukrainian War Thread How to buy a book - shipping from Korea to Europe The Games Industry And ATVI
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread Series you have seen recently... Movie Discussion! [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion MLB/Baseball 2023 McBoner: A hockey love story
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread Simple Questions Simple Answers FPS when play League Of Legend on laptop
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Hello guys!
LIN1s
Role of Gaming on Mental Hea…
TrAiDoS
ASL S22 English Commentary…
namkraft
Poker (part 2)
Nebuchad
An Exploration of th…
waywardstrategy
ramps on octagon
StaticNine
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7127 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
Poland17798 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
Poland17798 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
PiGosaur Cup
00:00
#91
PiGStarcraft104
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 112
PiGStarcraft104
FoxeR 42
StarCraft: Brood War
GuemChi 3842
Artosis 605
Purpose 18
Terrorterran 8
Dota 2
LuMiX1
League of Legends
Trikslyr66
Counter-Strike
summit1g7337
taco 326
minikerr79
Super Smash Bros
hungrybox515
Other Games
tarik_tv5832
JimRising 557
WinterStarcraft440
ViBE209
ToD206
JuggernautJason123
Organizations
Other Games
gamesdonequick1804
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• Hupsaiya 111
• EnkiAlexander 30
• OhrlRock 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• Scarra2150
Upcoming Events
The PondCast
8h 12m
Kung Fu Cup
9h 12m
OSC
22h 12m
CrankTV Team League
1d 9h
Replay Cast
1d 22h
CrankTV Team League
2 days
Korean StarCraft League
3 days
Afreeca Starleague
3 days
RSL Revival
3 days
Serral vs SHIN
herO vs Solar
Online Event
3 days
[ Show More ]
Replay Cast
3 days
RSL Revival
4 days
Clem vs ByuN
Rogue vs Lambo
WardiTV Weekly
5 days
Sparkling Tuna Cup
6 days
PiGosaur Cup
6 days
Liquipedia Results

Completed

Proleague 2026-07-21
HSC XXIX
Eternal Conflict S2 E3

Ongoing

CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026

Upcoming

Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
ESL Pro League Season 24
Stake Ranked Episode 4
Logitech G Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 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.