• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 03:42
CEST 09:42
KST 16:42
  • 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
[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists22
Community News
Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event11Code S Season 1 (2026) - RO12 Results12026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced9
StarCraft 2
General
Weekly Cups (April 27-May 4): Clem takes triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool 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
Tourneys
RSL Revival: Season 5 - Qualifiers and Main Event StarCraft Evolution League (SC Evo Biweekly) 2026 GSL Season 2 Qualifiers Sparkling Tuna Cup - Weekly Open Tournament $1,400 SEL Season 3 Ladder Invitational
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 524 Death and Taxes The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base
Brood War
General
Using AI to optimize marketing campaigns [ASL21] Ro8 Preview Pt2: Progenitors ASL21 General Discussion Why there arent any 256x256 pro maps? BW General Discussion
Tourneys
[ASL21] Ro8 Day 4 [ASL21] Ro8 Day 3 [Megathread] Daily Proleagues [ASL21] Ro8 Day 2
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV OutLive 25 (RTS Game) Daigo vs Menard Best of 10 Nintendo Switch Thread
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
Russo-Ukrainian War Thread US Politics Mega-thread European Politico-economics QA Mega-thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Movie Stars In Video Games: …
TrAiDoS
ramps on octagon
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1152 users

The Big Programming Thread - Page 535

Forum Index > General Forum
Post a Reply
Prev 1 533 534 535 536 537 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.
teamamerica
Profile Blog Joined July 2010
United States958 Posts
October 25 2014 20:23 GMT
#10681
On October 26 2014 03:34 Nesserev wrote:
Show nested quote +
On October 26 2014 03:18 teamamerica wrote:
Ya I guess I can't know what assumptions question had since I didn't ask - but assuming you can't buy-sell on same day, how would you handle that?

Well, if they don't want any losses and you can't buy-sell on the same day, then you could use this case (when buy and sell date are the same) to point out that you should never buy/sell.

My approach won't handle the problem 'If you need to have a buy or sell date, even when the stock prices are continuously decreasing, what days would you pick to minimize your losses', but your approach should handle it just fine, I think, no?


Only approach I've seen so far that handles a continuously decreasing array, where you can't buy/sell on any day, must perform some buy/sell is the approach of iterating through the combinations. dae, you, and I had the same code basically, and that doesn't handle it. Anyway, I've honestly stopped working on that for now, I'm just checking this thread for updates as to other people attempted to solve it.
RIP GOMTV. RIP PROLEAGUE.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
October 25 2014 23:45 GMT
#10682
i already asked, what do you want to do in the case where buying on any day would result in a loss? not buy? minimize loss? it's literally an if statement for the first case
There is no one like you in the universe.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
October 26 2014 00:03 GMT
#10683
--- Nuked ---
Biolunar
Profile Joined February 2012
Germany224 Posts
Last Edited: 2014-10-26 00:55:18
October 26 2014 00:53 GMT
#10684
Lah-tech, as everyone else does. Your environment is weird.
What is best? To crush the Zerg, see them driven before you, and hear the lamentations of the Protoss.
MichaelEU
Profile Joined February 2011
Netherlands816 Posts
October 26 2014 00:55 GMT
#10685
Lah-tech by most people, lay-tech by some native English speakers. Definitely not tex however.
世界を革命する力を!― znf: "Michael-oniichan ( *^▽^*)ノ✩キラ✩"
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
October 26 2014 01:10 GMT
#10686
Lay-Tech and Latex (the brand) are the only pronounciations I've ever heard :| I guess it's the native English vs non-native difference for anyone who says it with a Lah?
There is no one like you in the universe.
teamamerica
Profile Blog Joined July 2010
United States958 Posts
October 26 2014 01:41 GMT
#10687
On October 26 2014 08:45 Blisse wrote:
i already asked, what do you want to do in the case where buying on any day would result in a loss? not buy? minimize loss? it's literally an if statement for the first case



Sorry I've not made that clear - assume you're trying to minimize loss.
RIP GOMTV. RIP PROLEAGUE.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2014-10-26 02:42:15
October 26 2014 02:42 GMT
#10688
On October 25 2014 16:37 bangsholt wrote:
Show nested quote +
On October 25 2014 13:09 Blisse wrote:
On October 25 2014 05:55 bangsholt wrote:
On October 24 2014 06:47 Days wrote:
Yes I am using that API. Sorry about not providing links. I guess I just don't have experience serializing/deserializing JSON data in C#. I guess I have to do a bit more research xD


A few helpers then ;-)

https://www.nuget.org/packages/Microsoft.Net.Http

Specifically, HttpClient. Can do all sorts of requests and is async.

https://www.nuget.org/packages/Newtonsoft.Json/

JsonConverter is the best

http://json2csharp.com/

Saves time in creating objects to deserialize to.


What does Microsoft.Net.Http offer over using System.Net.WebClient and System.Net.Http.HttpClient? Never really used the Microsoft.Net offering.

I prefer using the JToken.FromObject and JToken.ToObject methods instead. Makes code much more portable I feel.


I was referring to System.Net.Http.HttpClient ;o)

Is JToken a standard interface of some sort, or why do you think it makes code more portable than JsonConverter?

I mostly care about compatibility with Xamarin.


Oh I see. Yeah I feel like the Nuget and the System.Net.Http.Httpclient offering are the same o;

JTokens are serialized json objects represented as c# objects. Basically you do the step "JToken jObject = JToken.FromObject(myObject);", passing in a normal object (marked up with DataContract/JsonProperty/Xml attributes), and it converts it to a JToken(JObject/JArray). Passing around the JToken is heavier weight because the JToken internally is represented by an actual json dictionary (meaning jObject["attribute"] is a valid operation), but that also means calling "jObject.ToString()" is a very light operation because the json has already been serialized.

I said it's probably more portable because unlike with a JsonConverter, we don't have to implement a custom JsonConverter when we have to serialize stuff, or even initialize one. Instead, we mark up the actual object with attributes stating the conditions of the serialization/deserialization, and we only have to move the classes around if the project changes, not both the classes and converters. Makes for fewer dependencies.

The only problem is that if we want to have complicated serialization/deserialization logic, attribute markup tends to be hard to debug and long listed. In that case I would prefer using jsonconverter, but I think that keeping it in jtoken form first is preferable and only move over to jsonconverters when it's required.
There is no one like you in the universe.
Manit0u
Profile Blog Joined August 2004
Poland17743 Posts
Last Edited: 2014-10-26 12:44:59
October 26 2014 04:46 GMT
#10689
On October 26 2014 10:10 Blisse wrote:
Lay-Tech and Latex (the brand) are the only pronounciations I've ever heard :| I guess it's the native English vs non-native difference for anyone who says it with a Lah?


How you change "la" to "lay" is beyond me. Tex as "tech" is because of this portion of the name is derived from Greek τέχ as in τέχνη (techne = art, skill).

In general, I'm reading it like that:

[L]-and
[A]-nthropomorphic
[T]-ime
[E]-ighty
[H]-elp

Here's how a greek pronounces τέχνη in μουσική τέχνη (music art): link
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2014-10-26 06:03:59
October 26 2014 06:03 GMT
#10690
--- Nuked ---
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2014-10-26 06:27:55
October 26 2014 06:25 GMT
#10691
http://m.youtube.com/watch?v=0seJ3g8uFcQ

You guys do know that's there's a material called latex that's pronounced laytex right?

And youtubing latex really only gives me pronunciations of laytex (material) or laytech (document language)
There is no one like you in the universe.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
October 26 2014 06:40 GMT
#10692
--- Nuked ---
Cynry
Profile Blog Joined August 2010
810 Posts
Last Edited: 2014-10-26 07:35:40
October 26 2014 07:34 GMT
#10693
Uh sooo, I'm confused and embarassed right now, but this :

void ft_putstr(char const *s);

char *ft_strclr(char *s)
{
int i;

i = 0;
while (s[i])
{
s[i] = '\0';
i++;
}
return (s);
}

int main(void)
{
char *str = "hello";

ft_putstr((char const *)str);
ft_putchar('\n');
str = ft_strclr(str);
ft_putstr((char const *)str);
ft_putchar('\n');
return (0);
}


segfault in the only loop there is and I can't for the life of me figure why. Yeah, I'm new to all that. Don't mind how weird/convoluted this may look, we have a strict set of rules at my school. "for" ? Forbidden. Built-in function ? Nah...
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2014-10-26 08:27:43
October 26 2014 08:14 GMT
#10694
--- Nuked ---
bangsholt
Profile Joined June 2011
Denmark138 Posts
Last Edited: 2014-10-26 08:38:49
October 26 2014 08:24 GMT
#10695
On October 26 2014 16:34 Cynry wrote:
Uh sooo, I'm confused and embarassed right now, but this :

void ft_putstr(char const *s);

char *ft_strclr(char *s)
{
int i;

i = 0;
while (s[i])
{
s[i] = '\0';
i++;
}
return (s);
}

int main(void)
{
char *str = "hello";

ft_putstr((char const *)str);
ft_putchar('\n');
str = ft_strclr(str);
ft_putstr((char const *)str);
ft_putchar('\n');
return (0);
}


segfault in the only loop there is and I can't for the life of me figure why. Yeah, I'm new to all that. Don't mind how weird/convoluted this may look, we have a strict set of rules at my school. "for" ? Forbidden. Built-in function ? Nah...


So you're segfaulting when you try to change a string literal, which would usually be put into read-only, which is where you segfault comes from.

Solution 1:
+ Show Spoiler +
So if you instead do,


char str[] = "hello";
char * str_ptr = str;


Now you allocate an array on the stack instead, (and probably do an implicit copy of "hello" from read-only) which can be manipulated. To satisfy the return value (which now is not used anymore), you need to add a pointer to a char - the str_ptr.

and replace


str = ft_strclr(str);

with

str_ptr = ft_strclr(str);


It all works.


Solution 2:
+ Show Spoiler +

You need to add two standard headers to use this.


#include <stdlib.h>
#include <string.h>


Then you change the following line


char *str = "hello";


to


/* 6 is length of "hello\n" */
char * str = calloc(sizeof(char), 6);
(void*) strncpy(str, "hello", 6);


Now it's instead a heap allocation, by using calloc, which again means you get a pointer back to where it has been allocated.

Then the "hello" is copied into the piece of memory that is allocated, and everything works as intended.

You should add a


free(str);


To make sure you don't leak memory now.


EDITs: Added explanation, added a second solution, removed extra tags

Silly learning examples are silly though ;o)
bangsholt
Profile Joined June 2011
Denmark138 Posts
October 26 2014 08:46 GMT
#10696
On October 26 2014 17:14 Nesserev wrote:
EDIT: Btw, why does your 'ft_strclr'-function return a char* ? Totally not necessary ... maybe an artefact from the code you had written before this?


This one I know the answer to - it's what you do with string functions in C, so that you can chain them

A bad example, because I can't come up with a good use right now.

char * str = malloc(sizeof(char) * 100);

strncpy(memset(str, 0, 100), "hello world", 100);


Yes, the exact same thing would be accomplished by using calloc rather than malloc... But details ;o)
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2014-10-26 09:11:57
October 26 2014 09:11 GMT
#10697
--- Nuked ---
Cynry
Profile Blog Joined August 2010
810 Posts
Last Edited: 2014-10-26 09:55:22
October 26 2014 09:33 GMT
#10698
Your school sucks balls...

Haha, well, considering what you know about it it may be debatable (although I quite enjoy the "from the ground up" approach), but trust me, this school rocks ^^ It's called 42, a french school recently opened, look it up if you want. No teacher, no schedule, I quite like it there :D

Anyway, thanks ! Definitely sounds right, it's actually "something I'm supposed to already know" ^^

Yes, the *char returned is an artifact, wanted to try if my function worked by putting a letter instead of \0.

@bangsholt
Thank you too ! Wondering, how about :
char str[] = "hello";

str = ft_strclr(&str[0]);

Would that work ? Guess it should, gonna try when I get back to work.

Oh wow, just man-ed calloc. Allocate AND initiate ? Sounds useful, no wonder it's forbidden ><
So far we can only use write, malloc and free... Yup.
And yeah these are rather boring learning exemples, but we really have to do them, since our first assignement is to recode ~60 functions of libc, from putchar to atoi, so as to make our own library to use during the course. Everything else is, of course, forbidden. We'll eventually have our own printf, malloc etc.

Edit : Calloc can initiate to something else than 0 ?? Oh my...

Edit 2 : What I wondered about doesn't work.
ft_strclr.c: In function ‘main’:
ft_strclr.c:22:6: error: incompatible types when assigning to type ‘char[6]’ from type ‘char *’
str = ft_strclr(&str[0])

Doesn't matter to finish this function, but I'm still curious as to why. There shouldn't be a char[6] with a 6 char long string, and the while in strclr should stop at [5] as it's a \0. What am I missing ?
bangsholt
Profile Joined June 2011
Denmark138 Posts
October 26 2014 10:41 GMT
#10699
On October 26 2014 18:33 Cynry wrote:
@bangsholt
Thank you too ! Wondering, how about :
char str[] = "hello";

str = ft_strclr(&str[0]);



Why are you passing the address of index 0 of str?

Passing str would do the same. This is one of the cases where an array is the same as a pointer.

On October 26 2014 18:33 Cynry wrote:
Edit 2 : What I wondered about doesn't work.
ft_strclr.c: In function ‘main’:
ft_strclr.c:22:6: error: incompatible types when assigning to type ‘char[6]’ from type ‘char *’
str = ft_strclr(&str[0])

Doesn't matter to finish this function, but I'm still curious as to why. There shouldn't be a char[6] with a 6 char long string, and the while in strclr should stop at [5] as it's a \0. What am I missing ?


And here is a case of an array not being the same as a pointer.

One way to view the use of a string literal, is that it will be expanded into something like this

char[6] str = {'h', 'e', 'l', 'l', 'o', '\0'};


That's where your char[6] comes from.

Why do you think that where the while loop stop holds any significance?
Cynry
Profile Blog Joined August 2010
810 Posts
Last Edited: 2014-10-26 10:56:07
October 26 2014 10:55 GMT
#10700
I thought that
char   str[] = "hello";

ft_strclr(&str[0]);


would be equivalent to
char   *str = "hello";

ft_strclr(str);

would be the same except that I would be able to modifiy the string in the first exemple, avoiding the error that brought me here in the first place because of the second exemple.

And here is a case of an array not being the same as a pointer.

One way to view the use of a string literal, is that it will be expanded into something like this

char[6] str = {'h', 'e', 'l', 'l', 'o', '\0'};



That's where your char[6] comes from.

Why do you think that where the while loop stop holds any significance?


I misinterpreted the error. Thought that char[6] pointed to the 7th character (starting at char[0]) and that the while loop was responsible for the error, trying to go too far or something like that (would have been another segfault I guess).
Now if I understand correctly, char[6] simply is an array of 6 char, \0 included, and the error comes from the fact that ft_strclr returns a char *. Correct ?
Prev 1 533 534 535 536 537 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 2h 18m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nina 142
StarCraft: Brood War
Sea 3592
Killer 263
Aegong 80
Mind 76
scan(afreeca) 51
910 50
Shinee 47
Dewaltoss 39
Hyuk 25
ZergMaN 20
[ Show more ]
NotJumperer 10
Bale 9
League of Legends
JimRising 601
Super Smash Bros
Mew2King84
Other Games
summit1g7064
ceh9514
C9.Mang0407
Happy277
monkeys_forever170
NeuroSwarm62
Organizations
Other Games
gamesdonequick763
Dota 2
PGL Dota 2 - Main Stream44
StarCraft: Brood War
lovetv 13
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• LUISG 4
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1566
• TFBlade921
• Stunt530
Upcoming Events
Sparkling Tuna Cup
2h 18m
Afreeca Starleague
2h 18m
Snow vs Flash
WardiTV Invitational
3h 18m
SHIN vs Nicoract
Solar vs Nice
PiGosaur Cup
16h 18m
GSL
1d 1h
Classic vs Cure
Maru vs Rogue
GSL
2 days
SHIN vs Zoun
ByuN vs herO
OSC
2 days
OSC
2 days
Replay Cast
2 days
Escore
3 days
[ Show More ]
The PondCast
3 days
WardiTV Invitational
3 days
Zoun vs Ryung
Lambo vs ShoWTimE
OSC
3 days
Replay Cast
3 days
CranKy Ducklings
4 days
RSL Revival
4 days
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
4 days
Krystianer vs TriGGeR
Cure vs Rogue
uThermal 2v2 Circuit
4 days
BSL
4 days
Replay Cast
4 days
Sparkling Tuna Cup
5 days
RSL Revival
5 days
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
5 days
BSL
5 days
GSL
6 days
Afreeca Starleague
6 days
Liquipedia Results

Completed

Proleague 2026-05-02
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
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

YSL S3
Escore Tournament S2: W6
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
Escore Tournament S2: W7
Escore Tournament S2: W8
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.