• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 07:59
CEST 13:59
KST 20:59
  • 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!19Weekly Cups (July 13-19): Terran & Protoss rise; Zerg falters2Balance hotfix patch 5.0.16b (July 16)88Reynor: 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) How would you feel about frequent/monthly balance patches for SC2? Clem: "I don't have that much hope in Blizzard" Weekly Cups (July 13-19): Terran & Protoss rise; Zerg falters [D] Wireframe Casting Removed
Tourneys
IntoTheTV X SOOP SC2 League : Weekly & Monthly INu's Battles#18 - Cure, herO, Rogue & ByuN RSL Revival: Season 6 - Qualifiers and Main Event Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026
Strategy
[G] Having the right mentality to improve
Custom Maps
[M] (2) Industrial Park New Map Maker - Looking for Advice - Love or Hate
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/ Animated Gateway BW General Discussion HORROR STARCRAFT MOVIE How Famous was FlaSh before his Debut?
Tourneys
Escore Tournament - Season 3 [Megathread] Daily Proleagues [IPSL] Spring 2026 Grand Finals - This Weekend! 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
Path of Exile ZeroSpace Early Access is Now Live! Nintendo Switch Thread General RTS Discussion Thread Diablo IV
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
Artificial Intelligence Thread US Politics Mega-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
How Games can Help with Majo…
TrAiDoS
Hello guys!
LIN1s
ASL S22 English Commentary…
namkraft
Poker (part 2)
Nebuchad
An Exploration of th…
waywardstrategy
Customize Sidebar...

Website Feedback

Closed Threads



Active: 3995 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
Poland17799 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
CrankTV Team League
11:00
Crank Gathers S4: Playoffs
LiquipediaDiscussion
KCM Race Survival
10:00
2026 Season 3 Week 3
Kim Chul Min (afreeca) 1555
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko390
RotterdaM 192
Rex 37
StarCraft: Brood War
Rain 5527
Calm 4347
BeSt 2179
910 2177
Bisu 1217
Zeus 1009
Jaedong 733
firebathero 599
Horang2 589
Mini 382
[ Show more ]
EffOrt 285
Soma 244
Soulkey 219
Snow 214
Light 196
Stork 172
actioN 165
Last 127
Dewaltoss 113
Hyun 111
Rush 108
Mong 93
Mind 92
Larva 87
Pusan 76
ggaemo 62
ToSsGirL 51
Sea.KH 35
sorry 33
Shine 30
Bale 29
Movie 29
hero 29
yabsab 25
JYJ 24
[sc1f]eonzerg 23
Sacsri 22
Sexy 21
Barracks 19
Sharp 18
Terrorterran 18
HiyA 17
zelot 16
JulyZerg 16
ajuk12(nOOB) 13
IntoTheRainbow 12
Yoon 10
Noble 8
Dota 2
Dendi513
XcaliburYe122
Counter-Strike
shoxiejesuss942
fl0m889
markeloff468
edward68
Other Games
gofns12170
singsing2199
FrodaN2192
B2W.Neo487
crisheroes291
uThermal171
OGKoka 163
Sick157
Liquid`LucifroN123
CosmosSc2 24
Trikslyr13
Organizations
StarCraft 2
WardiTV68
StarCraft: Brood War
UltimateBattle 36
StarCraft 2
angryscii 21
StarCraft: Brood War
lovetv 14
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2179
• WagamamaTV311
League of Legends
• Jankos2007
• TFBlade707
Upcoming Events
WardiTV Summer Champion…
2m
Replay Cast
12h 2m
Escore
22h 2m
CrankTV Team League
23h 2m
Big Brain Bouts
1d 4h
Soulspirit vs goblin
TriGGeR vs Bunny
Korean StarCraft League
1d 15h
Afreeca Starleague
1d 16h
RSL Revival
1d 21h
Serral vs SHIN
herO vs Solar
Online Event
2 days
Replay Cast
2 days
[ Show More ]
RSL Revival
2 days
Clem vs ByuN
Rogue vs Lambo
OSC
3 days
WardiTV Weekly
3 days
Sparkling Tuna Cup
4 days
INu's Battles
4 days
Cure vs herO
ByuN vs Rogue
PiGosaur Cup
5 days
The PondCast
5 days
Kung Fu Cup
5 days
Patches Events
6 days
Replay Cast
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Proleague 2026-07-22
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
ASL Season 22: Qualifier #1
ASL Season 22: Qualifier #2
CSLAN 4
ASL Season 22
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.