• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 17:17
CET 23:17
KST 07:17
  • 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 Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
RSL Season 3: RO16 results & RO8 bracket13Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge1[TLMC] Fall/Winter 2025 Ladder Map Rotation14Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA12
StarCraft 2
General
RSL Season 3: RO16 results & RO8 bracket SC: Evo Complete - Ranked Ladder OPEN ALPHA RSL Season 3 - Playoffs Preview Mech is the composition that needs teleportation t GM / Master map hacker and general hacking and cheating thread
Tourneys
RSL Revival: Season 3 $5,000+ WardiTV 2025 Championship StarCraft Evolution League (SC Evo Biweekly) Constellation Cup - Main Event - Stellar Fest 2025 RSL Offline Finals Dates + Ticket Sales!
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened
Brood War
General
Data analysis on 70 million replays soO on: FanTaSy's Potential Return to StarCraft BGH Auto Balance -> http://bghmmr.eu/ A cwal.gg Extension - Easily keep track of anyone [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO16 Tie Breaker - Group A - Sat 21:00 CET [Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] GosuLeague T1 Ro16 - Tue & Thu 22:00 CET
Strategy
Game Theory for Starcraft Current Meta How to stay on top of macro? PvZ map balance
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Clair Obscur - Expedition 33 EVE Corporation [Game] Osu!
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
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread The Games Industry And ATVI Things Aren’t Peaceful in Palestine About SC2SEA.COM
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread Korean Music Discussion
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
The Health Impact of Joining…
TrAiDoS
Dyadica Evangelium — Chapt…
Hildegard
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1945 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
Poland17450 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
Poland17450 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
BSL 21
20:00
RO16 TieBreaker - Group A
TerrOr vs Aeternum
HBO vs Kyrie
ZZZero.O284
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
White-Ra 335
Nathanias 135
StarCraft: Brood War
Calm 962
ZZZero.O 284
Dewaltoss 100
NaDa 45
Rock 45
Noble 14
Dota 2
PGG 58
Counter-Strike
fl0m1465
adren_tv111
Heroes of the Storm
Khaldor238
Other Games
Grubby6155
FrodaN3028
Mlord602
Liquid`Hasu349
mouzStarbuck123
KnowMe122
Trikslyr51
Organizations
Other Games
EGCTV1353
gamesdonequick1066
StarCraft: Brood War
lovetv 8
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• Hupsaiya 58
• musti20045 4
• Kozan
• sooper7s
• AfreecaTV YouTube
• Migwel
• LaughNgamezSOOP
• intothetv
• IndyKCrew
StarCraft: Brood War
• 80smullet 12
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 7022
• masondota21352
• WagamamaTV615
• Ler114
• lizZardDota278
Other Games
• imaqtpie1489
• Shiphtur315
Upcoming Events
RSL Revival
9h 13m
Classic vs SHIN
Maru vs TBD
herO vs TBD
Wardi Open
15h 43m
IPSL
21h 43m
StRyKeR vs OldBoy
Sziky vs Tarson
BSL 21
21h 43m
StRyKeR vs Artosis
OyAji vs KameZerg
OSC
1d
OSC
1d 10h
Monday Night Weeklies
1d 18h
OSC
2 days
Wardi Open
2 days
Replay Cast
3 days
[ Show More ]
Wardi Open
3 days
Tenacious Turtle Tussle
4 days
The PondCast
4 days
Replay Cast
5 days
LAN Event
5 days
Replay Cast
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-11-21
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 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.