• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 00:07
CEST 06:07
KST 13:07
  • 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
[ASL22] Ro16 Preview: Rough Waters10[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915Serral wins Maestros of the Game 244
Community News
StarCraft open world shooter announced at BlizzCon54Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism10Official StarCraft website teases new content ahead of BlizzCon?160Stellar Fest TWO the Moon (Dec 16-20)9Weekly Cups (August 24-30): Patches' balance mod takes over3
StarCraft 2
General
StarCraft open world shooter announced at BlizzCon How do you feel about the StarCraft shooter announcement at BlizzCon 2026? Balance hotfix patch 5.0.16b (July 16) Team Liquid Map Contest #22: Results and Winners Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism
Tourneys
RSL goes to London! 2026 Offline Finals Nov 21-22 KSL Week #92 IntoTheTV X SOOP SC2 League : Weekly & Monthly 2026 GSTL Announcement Sparkling Tuna Cup - Weekly Open Tournament
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 542 The Ascended Mutation # 541 Binary Choice The PondCast: SC2 News & Results Mutation # 540 Dodge This
Brood War
General
Official StarCraft website teases new content ahead of BlizzCon? BGH Auto Balance -> http://bghmmr.eu/ Broodwar Prediction Market Practice Partners (Official) [D] Brainstorming a balance patch for Brood war
Tourneys
[ASL22] Ro16 Group A [ASL22] Ro16 Group B Escore Tournament - Season 3 Small VOD Thread 2.0
Strategy
Replay Review Process - What do you do? Simple Questions, Simple Answers Odyssey Mineral Stack Saturation Game Theory for Starcraft
Other Games
General Games
EVE Corporation Diablo IV Nintendo Switch Thread [Maplestory Hardcore] Let's Play~!! General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
Trading/Investing Thread US Politics Mega-thread UK Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
Diablo Animated Series on Netflix Movie Discussion!
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Virtual Romance, Real-Life C…
TrAiDoS
Regacy Esports:Our Goa…
regacyesports
Dreaming of BW patches (mod…
c3rberUs
LOCKPICKING NOOB
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7121 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
Poland17843 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
OSC
20:30
Masters Cup #151
davetesta46
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 303
StarCraft: Brood War
Aegong 69
yabsab 10
Icarus 7
Dota 2
NeuroSwarm194
LuMiX1
Other Games
summit1g12470
JimRising 580
PiGStarcraft318
ViBE158
Organizations
Other Games
BasetradeTV217
[ Show 11 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota22102
League of Legends
• Lourlo1045
• Stunt177
Upcoming Events
Sparkling Tuna Cup
5h 53m
WardiTV Invitational
6h 53m
ByuN vs Percival
Cure vs Classic
Shopify Rebellion Sundays
10h 53m
Spirit vs Mixu
Clem vs TBD
RSL Revival
11h 53m
Serral vs Rogue
BlizzCon
14h 23m
IdrA vs MC
Replay Cast
19h 53m
Afreeca Starleague
1d 5h
Light vs JyJ
Soulkey vs hero
WardiTV Weekly
1d 6h
Monday Night Weeklies
1d 11h
Afreeca Starleague
2 days
Snow vs Shinee
Shine vs EffOrt
[ Show More ]
GSL
2 days
PiGosaur Cup
2 days
The PondCast
3 days
Kung Fu Cup
3 days
Replay Cast
3 days
KCM Race Survival
4 days
IntoTheTV X SOOP
4 days
Replay Cast
4 days
IntoTheTV X SOOP
5 days
Replay Cast
5 days
GSL
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Acropolis #5 - TRS
PiG Sty Festival 8.0
Big Dog Cup 2026 Div 1

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
Acropolis #5
Blizzard Classic Cup 2026
Blizzard Classic Cup 2026
RSL Revival: Season 6
Calamity Invitational
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Acropolis #5 - GSA
Acropolis #5 - GSB
Acropolis #5 - GSC
SC4ALL II: Brood War
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 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.