• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 04:16
CET 10:16
KST 18:16
  • 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
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
RSL Offline Finals Info - Dec 13 and 14! StarCraft Evolution League (SC Evo Biweekly) RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Nintendo Switch Thread ZeroSpace Megathread Stormgate/Frost Giant Megathread The Perfect Game Path of Exile
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 TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1614 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
Poland17496 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 44m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 154
-ZergGirl 56
StarCraft: Brood War
Britney 26052
GuemChi 694
Tasteless 287
BeSt 276
Killer 164
Pusan 97
Sacsri 93
Mini 81
Sharp 69
Dewaltoss 62
[ Show more ]
sorry 52
ToSsGirL 40
Shine 36
Shinee 33
ggaemo 28
Rush 22
ZergMaN 21
Bale 16
soO 8
Hm[arnc] 7
Noble 5
Dota 2
febbydoto148
NeuroSwarm99
Fuzer 53
canceldota46
League of Legends
JimRising 473
C9.Mang0265
Reynor63
Counter-Strike
shoxiejesuss491
olofmeister156
Super Smash Bros
Westballz28
Other Games
summit1g11767
WinterStarcraft593
ceh9387
crisheroes368
Happy276
Mew2King34
Organizations
Other Games
gamesdonequick580
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• LUISG 24
• Light_VIP 13
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota232
League of Legends
• Lourlo1022
• Jankos679
Upcoming Events
The PondCast
44m
OSC
6h 44m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
14h 44m
Korean StarCraft League
1d 17h
CranKy Ducklings
2 days
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
3 days
[ Show More ]
WardiTV 2025
3 days
OSC
3 days
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
3 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
4 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
5 days
StarCraft2.fi
6 days
Tenacious Turtle Tussle
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
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
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 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.