• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 13:05
CEST 19:05
KST 02:05
  • 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] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915Serral wins Maestros of the Game 244ByuL, and the Limitations of Standard Play3
Community News
New 3v3 BGH Ladder (and more) on ShieldBattery!29Weekly Cups (August 17-23): Zerg dominate the week5Weekly Cups (August 10-16): SHIN doubles2GSTL Returns in 2026!45Weekly Cups (Aug 3-9): Protoss get shut out7
StarCraft 2
General
SC4ALL II: SC2 Player Announcement 6/8 - Maru SC2 best pvp 2026 game hypothesis Balance hotfix patch 5.0.16b (July 16) Weekly Cups (August 17-23): Zerg dominate the week Starcraft2 player guess game is Coming~!
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament 2026 GSTL Announcement IntoTheTV X SOOP SC2 League : Weekly & Monthly PIG STY FESTIVAL 8.0! (13 - 23 August) WORTEX 2026 - Hungarian SC2 Finals Budapest
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 540 Dodge This The PondCast: SC2 News & Results Mutation # 539 Thunder Dome Mutation # 538 Media Blackout
Brood War
General
BW General Discussion New 3v3 BGH Ladder (and more) on ShieldBattery! [ASL22] Ro24 Preview: Siren's Call Farewell Beloved Starcraft (Youtube Videos) BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL22] Ro24 Group F Escore Tournament - Season 3 KCM Race Survival 2026 Season 3 [ASL22] Ro24 Group E
Strategy
Game Theory for Starcraft Replay Review Process - What do you do? Odyssey Mineral Stack Saturation Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread General RTS Discussion Thread Anyone here play Quakeworld back in the day? Stormgate/Frost Giant Megathread EVE Corporation
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 Power Rank TL Mafia Community Thread NeO.D_StephenKing vs This Guy From 1 Million Dance
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Russo-Ukrainian War Thread Dating: How's your luck? Artificial Intelligence Thread
Fan Clubs
The Creator Fan Club MarineLorD Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! Anime Discussion Thread
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023 NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Violent Games and Crime Rate…
TrAiDoS
LOCKPICKING NOOB
LUCKY_NOOB
Cathedral Of CS And NY pizza a…
FuDDx
Please support my new stand…
Peanutsc
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8976 users

The Big Programming Thread - Page 774

Forum Index > General Forum
Post a Reply
Prev 1 772 773 774 775 776 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.
Birdie
Profile Blog Joined August 2007
New Zealand4438 Posts
Last Edited: 2016-10-06 03:59:58
October 06 2016 03:56 GMT
#15461
While I could be wrong I was under the impression that ca WOULD be null terminated.
const char ca[] = { 'h', 'e', 'y' };

should assign 4 bytes and place h e y \0 in them.

The output would be:
h
e
y
Red classic | A butterfly dreamed he was Zhuangzi | 4.5k, heading to 5k as support!
beg
Profile Blog Joined May 2010
991 Posts
October 06 2016 04:04 GMT
#15462
I just had genius idea *cough cough*

cout << size(ca);

It returns 3, so I guess the while loop really is undefined eventually. Thanks for inspiring me, Birdie^^
Birdie
Profile Blog Joined August 2007
New Zealand4438 Posts
October 06 2016 04:18 GMT
#15463
On October 06 2016 13:04 beg wrote:
I just had genius idea *cough cough*

cout << size(ca);

It returns 3, so I guess the while loop really is undefined eventually. Thanks for inspiring me, Birdie^^

The size() function returns the length of the string excluding the null terminator. sizeof(ca) would be much more relevant to what you want to know.
Red classic | A butterfly dreamed he was Zhuangzi | 4.5k, heading to 5k as support!
beg
Profile Blog Joined May 2010
991 Posts
Last Edited: 2016-10-06 04:27:08
October 06 2016 04:26 GMT
#15464
Weird, I tested size() on

char c1[] = { '\0' };
char c2[] = { '\0', '\0' };

and it did return the number of null terminators.

Anyway. I checked sizeof(ca) and it returned the same numbers. So thanks again.



(The bazillion details of C++ ... )
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
October 06 2016 06:05 GMT
#15465
To it turns out if I put a scanf("%c" right under scanf("%d", the scanf for char thinks that the enter button that I pressed right after entering the integer value is for him. What a bullshit.
"windows bash is a steaming heap of shit" tofucake
Birdie
Profile Blog Joined August 2007
New Zealand4438 Posts
October 06 2016 06:34 GMT
#15466
Yup learned that pretty early on at uni, there's different ways around it like calling getch() right after if I recall correctly, been a while though. It doesn't clear the newline from the stdio buffer IIRC.
Red classic | A butterfly dreamed he was Zhuangzi | 4.5k, heading to 5k as support!
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
Last Edited: 2016-10-06 06:45:30
October 06 2016 06:43 GMT
#15467
nvm
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
October 06 2016 07:12 GMT
#15468
On October 06 2016 15:34 Birdie wrote:
Yup learned that pretty early on at uni, there's different ways around it like calling getch() right after if I recall correctly, been a while though. It doesn't clear the newline from the stdio buffer IIRC.

Calling getchar() right in between worked for me, but I'm pretty sure it wouldn't work if my eol was \r\n. Still need to learn how to clear input buffer.
"windows bash is a steaming heap of shit" tofucake
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 06 2016 07:26 GMT
#15469
On October 06 2016 16:12 Djagulingu wrote:
Show nested quote +
On October 06 2016 15:34 Birdie wrote:
Yup learned that pretty early on at uni, there's different ways around it like calling getch() right after if I recall correctly, been a while though. It doesn't clear the newline from the stdio buffer IIRC.

Calling getchar() right in between worked for me, but I'm pretty sure it wouldn't work if my eol was \r\n. Still need to learn how to clear input buffer.


Essentially you'll want to not use scanf in the first place. Use fgets and parse the whole line instead.
scanf is a fairly dangerous function, because it doesn't check for overflow and causes problems when users enter nonsense - as users tend to do.

There are methods to clear the input buffer, but they are all not very portable or reliable.
BluzMan
Profile Blog Joined April 2006
Russian Federation4235 Posts
October 06 2016 09:25 GMT
#15470
On October 06 2016 12:32 beg wrote:
Hope no one minds me asking a few C++ questions every now and then :S
So, I'm wondering about an excersise from the book C++ Primer.

"What does this code do?"

const char ca[] = { 'h', 'e', 'y' };
const char *cp = ca;

while (*cp)
{
cout << *cp << endl;
++cp;
}


Sooo, cp is a pointer to &ca[0] and we keep incrementing it until we encounter *cp == 0.
But... ca[] is not null-terminated. I was thinking the while loop should eventually show undefined behaviour, but everytime I run this code it seems to work fine.

Is it undefined? If not, what am I missing?


You're perfectly right, this is undefined behavior which might include "working alrite" because by some twist of luck ca ended up in zero-filled memory. Try playing with optimisation flags, you might get different results with say, -O3.
You want 20 good men, but you need a bad pussy.
tofucake
Profile Blog Joined October 2009
Hyrule19246 Posts
October 06 2016 12:47 GMT
#15471
On October 06 2016 18:25 BluzMan wrote:
Show nested quote +
On October 06 2016 12:32 beg wrote:
Hope no one minds me asking a few C++ questions every now and then :S
So, I'm wondering about an excersise from the book C++ Primer.

"What does this code do?"

const char ca[] = { 'h', 'e', 'y' };
const char *cp = ca;

while (*cp)
{
cout << *cp << endl;
++cp;
}


Sooo, cp is a pointer to &ca[0] and we keep incrementing it until we encounter *cp == 0.
But... ca[] is not null-terminated. I was thinking the while loop should eventually show undefined behaviour, but everytime I run this code it seems to work fine.

Is it undefined? If not, what am I missing?


You're perfectly right, this is undefined behavior which might include "working alrite" because by some twist of luck ca ended up in zero-filled memory. Try playing with optimisation flags, you might get different results with say, -O3.

It's not undefined behavior. The compiler automatically adds a null on the end of the array, and sizeof doesn't count it. It doesn't matter what optimization is done. If you want to create undefined behavior you would need to declare the array with malloc, then instantiate with your characters. The compiler won't automatically add a null in that case.
Liquipediaasante sana squash banana
beg
Profile Blog Joined May 2010
991 Posts
Last Edited: 2016-10-06 13:37:10
October 06 2016 13:36 GMT
#15472
I'm sorry for kicking off this discussion with so much disagreement ~
Anyway, I'm somewhat sure I figured it out now.


char ca[] = "hey"; //null-terminator added!
sizeof(ca) == 4; //true
size(ca) == 4; //true



But:
char ca[] = { 'h', 'e', 'y' }; //no null-terminator!
sizeof(ca) == 3; //true
size(ca) == 3; //true



This method of testing didn't come to my mind. I should have slept over this another night...
Acrofales
Profile Joined August 2010
Spain18424 Posts
October 06 2016 13:54 GMT
#15473
On October 06 2016 22:36 beg wrote:
I'm sorry for kicking off this discussion with so much disagreement ~
Anyway, I'm somewhat sure I figured it out now.


char ca[] = "hey"; //null-terminator added!
sizeof(ca) == 4; //true
size(ca) == 4; //true



But:
char ca[] = { 'h', 'e', 'y' }; //no null-terminator!
sizeof(ca) == 3; //true
size(ca) == 3; //true



This method of testing didn't come to my mind. I should have slept over this another night...

Sure, that makes sense. But it doesn't explain why your initial code worked properly: why was that null terminator added? Was it by chance? Was it some kind of magic that means it will always work properly for type char? Or always work properly in whatever OS you're using?
iaretehnoob
Profile Joined June 2004
Sweden741 Posts
October 06 2016 15:31 GMT
#15474
1) Yes, string literals get null terminated automatically, character arrays do not.
2) The most likely reason the original code worked properly is zero-initialization of memory in a debug build. Just in case it isn't obvious: The while loop doesn't check for '\0', it checks for 0. But it could also be some form of buffer overflow prevention or divine intervention.
Hhanh00
Profile Joined May 2016
34 Posts
October 06 2016 16:00 GMT
#15475
On October 06 2016 22:36 beg wrote:
I'm sorry for kicking off this discussion with so much disagreement ~
Anyway, I'm somewhat sure I figured it out now.


char ca[] = "hey"; //null-terminator added!
sizeof(ca) == 4; //true
size(ca) == 4; //true



But:
char ca[] = { 'h', 'e', 'y' }; //no null-terminator!
sizeof(ca) == 3; //true
size(ca) == 3; //true



This method of testing didn't come to my mind. I should have slept over this another night...


Just to clarify a few things.
"hey" is null terminated because it is a string constant.

http://aboutc.weebly.com/string-constants.html
2) Every string constant ends up with a NULL character which is automatically assigned (before the closing double quotation mark) by the compiler.

In the code below,


#include <stdio.h>

void f(char r[]) {
printf("%d\n", sizeof(r));
}

int main() {
char *p = "hey";
char q[] = "hey";
char r[3] = "hey";
char s[2] = "hey";

printf("%d %d %d\n", sizeof(p), sizeof(q), sizeof(r));
f(p);
f(q);
return 0;
}


p is a pointer (not an array of char). so sizeof(p) is 8 on a 64 bit machine
q is an array initialized to 'h', 'e', 'y', '\0' and sizeof(q) is 4. The size is automatically determined by the initializer list.
r works too because it has a length equal to the sizeof("hey")-1. So r is non null terminated and sizeof(r) = 3
Now s is allowed too but will produce a warning (on gcc) because it is too short. You can also use a larger size and the array will be padded with 0.

The argument of f is not an array but a pointer. So sizeof(r) is 8 when called as f(p) and f(q). q is converted to the pass the address of its first element.

sizeof is a compile time expression and can't tell you the length of runtime string. It behaves very differently from strlen.


wchar_t t[] = L"hey";


sizeof(t) = 8, wcslen(t) = 3

Finally, p is pointer to static storage. You can't change it. p[0] = 'a' is undefined (it will probably segfault because static data is in a protected segment). But q, r, s are char arrays and you can modify them. q[0] = 'a' is ok.


Hope it helps
toadtoad
Profile Joined October 2016
9 Posts
Last Edited: 2016-10-06 16:16:41
October 06 2016 16:15 GMT
#15476
Hey guys, I was a sysadmin for 3 years, created a plethora of scripts and tools during my work. I now moved into business programming and building CRUD apps daily, I feel like I'm getting burned out much quicker than my sysadmins days, however the pay is much better, so I stuck with it. But now I'm re-considering.

I was wondering if anyone had done the opposite, so moving from a pure programming position to a IT OP/sysadmin position, if you did, how do you feel? do you feel like creating scripts and managing stuff less tiring? Do you regret your choice

Thanks,
mantequilla
Profile Blog Joined June 2012
Turkey781 Posts
October 06 2016 16:59 GMT
#15477
I really need some direction regarding windows azure (10 days no progress). Although people familiar with other cloud providers can help out too, it's not a very specific solution.

I am trying to find out how I am supposed to realize this scenario:

Clients visit my website, purchase my web app by filling out a form. Cloud does not play any role yet. Then, I need to deploy my app to azure and send customer an email containing the url of app, admin username/pass etc. required info. Or similarly, a client requests a trial of my web app, then I deploy a trial instance to azure.

Question is how am I supposed to deploy an app to cloud programmatically (automatically) ?

Azure has a web portal with a good interface, it is easy to deploy and configure things like tomcat, mysql etc manually. But I need to do that programmatically, since I can't deploy and configure every instance. I need to create tomcat, mysql and upload some configuration files and configure env variables:

- powershell, there are various examples that use powershell scripts to manage azure services but they are
1) too cryptic, I don't know what a wall of commands do. 2) I need a windows server to run these and integrate them with my website so after purchase these commands can be run. And what happens something doesn't work? Powershell scripts can't debug, log etc..

- azure management rest api: the api is huge and finding out what parameters needs to be sent in what format, plus writing a custom rest client for this, is not an easy job

- azure sdk, there are some examples using azure sdk to create resource groups etc. but I couldn't find how the heck can I create a tomcat or mysql containers and upload files to them... And I feel like java sdk does not cover all azure functionality, I may need to write a .net app for this (don't know if .net sdk is more complete)

What is the usual way to perform such a task with cloud providers? Do I need a 3rd party tool, or is it a trivial thing that I don't know how to do?
Age of Mythology forever!
BluzMan
Profile Blog Joined April 2006
Russian Federation4235 Posts
Last Edited: 2016-10-06 17:19:52
October 06 2016 17:14 GMT
#15478
On October 06 2016 21:47 tofucake wrote:
Show nested quote +
On October 06 2016 18:25 BluzMan wrote:
On October 06 2016 12:32 beg wrote:
Hope no one minds me asking a few C++ questions every now and then :S
So, I'm wondering about an excersise from the book C++ Primer.

"What does this code do?"

const char ca[] = { 'h', 'e', 'y' };
const char *cp = ca;

while (*cp)
{
cout << *cp << endl;
++cp;
}


Sooo, cp is a pointer to &ca[0] and we keep incrementing it until we encounter *cp == 0.
But... ca[] is not null-terminated. I was thinking the while loop should eventually show undefined behaviour, but everytime I run this code it seems to work fine.

Is it undefined? If not, what am I missing?


You're perfectly right, this is undefined behavior which might include "working alrite" because by some twist of luck ca ended up in zero-filled memory. Try playing with optimisation flags, you might get different results with say, -O3.

It's not undefined behavior. The compiler automatically adds a null on the end of the array, and sizeof doesn't count it. It doesn't matter what optimization is done. If you want to create undefined behavior you would need to declare the array with malloc, then instantiate with your characters. The compiler won't automatically add a null in that case.


You're wrong, it doesn't. It only automatically adds terminators to string literals, not arbitrary arrays of char.

Undefined behaviour means literally "anything can happen" and since your code working as intended falls under "anything", it can happen too. But might change at any moment. Furthermore, compilers often use detectable cases of UB as a source of information (compilers assume that code is well-formed and might for example flag code that triggers UB as unreachable) which may result in completely magical and non-obvious code transformations.
You want 20 good men, but you need a bad pussy.
beg
Profile Blog Joined May 2010
991 Posts
Last Edited: 2016-10-06 22:24:35
October 06 2016 17:52 GMT
#15479
On October 06 2016 22:54 Acrofales wrote:
Show nested quote +
On October 06 2016 22:36 beg wrote:
I'm sorry for kicking off this discussion with so much disagreement ~
Anyway, I'm somewhat sure I figured it out now.


char ca[] = "hey"; //null-terminator added!
sizeof(ca) == 4; //true
size(ca) == 4; //true



But:
char ca[] = { 'h', 'e', 'y' }; //no null-terminator!
sizeof(ca) == 3; //true
size(ca) == 3; //true



This method of testing didn't come to my mind. I should have slept over this another night...

Sure, that makes sense. But it doesn't explain why your initial code worked properly: why was that null terminator added? Was it by chance? Was it some kind of magic that means it will always work properly for type char? Or always work properly in whatever OS you're using?

Tested it on three different compilers, Win10 and Linux. The program always worked as if the char array was null terminated. So weird.


@Hhanh00:
I enjoyed going through your code as a mental excersise. Thanks for that. On a sidenote, I'm using C++, so the following examples were actually illegal (because "hey" is const char [4])
char r[3] = "hey";
char s[2] = "hey";



@everyone else:
Thanks for all the other contributions to my question. Not gonna quote everyone now, hehe.
Gonna lay this case to rest and blame some hidden compiler magic (or divine intervention.... or simply undefined behaviour).
Requizen
Profile Blog Joined March 2011
United States33802 Posts
October 06 2016 19:45 GMT
#15480
Any game devs on here?

I missed the GameMaker bundle on Humble Bundle last month, and while Clickteam Fusion seems like a much lesser tool, $15 seems like a good deal. I was just thinking of making some simple phone games as a hobby, would it be a good enough tool? Or is there something free out there that's worth checking out?
It's your boy Guzma!
Prev 1 772 773 774 775 776 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 6h 56m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
EnDerr 114
Trap 28
SHIN 18
StarCraft: Brood War
Britney 42081
Calm 4444
Shuttle 746
Mini 536
ggaemo 170
Rush 140
Dewaltoss 129
Snow 119
Yoon 112
hero 71
[ Show more ]
910 27
Sexy 25
Aegong 18
Terrorterran 14
soO 10
Dota 2
qojqva4708
Counter-Strike
fl0m3734
pashabiceps1023
x6flipin591
Other Games
Gorgc3954
Grubby2712
Liquid`RaSZi1183
crisheroes562
FrodaN522
Beastyqt479
Hui .158
KnowMe98
Mew2King94
QueenE59
Trikslyr43
[ Show 16 non-featured ]
StarCraft 2
• StrangeGG 50
• mYiSmile146
• Shameless 35
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2150
League of Legends
• Nemesis2773
• TFBlade625
Other Games
• Shiphtur316
• imaqtpie2
Upcoming Events
Replay Cast
6h 56m
Escore
16h 56m
IntoTheTV X SOOP
17h 56m
RotterdaM Event
23h 26m
Korean StarCraft League
1d 8h
GSL
1d 17h
Replay Cast
2 days
Sparkling Tuna Cup
2 days
WardiTV Weekly
2 days
Afreeca Starleague
3 days
[ Show More ]
GSL
4 days
PiGosaur Cup
5 days
Replay Cast
6 days
The PondCast
6 days
Liquipedia Results

Completed

CSL Season 22: Qualifier 1
PiG Sty Festival 8.0
META DYMY #4

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL Season 22: Qualifier 2
RSL Revival: Season 6
Light Tournament 2026
BLAST Open Fall 2026
Esports World Cup 2026
Esports World Cup 2026: LCQ
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026

Upcoming

BSL 2026 LAN: Kraków
CSL 2026 AUTUMN (S22)
Acropolis #5
Acropolis #5 - TRS
Blizzard Classic Cup 2026
Acropolis #5 - GSA
Acropolis #5 - GSB
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
Calamity Invitational
Big Dog Cup 2026 Div 1
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
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
FISSURE Playground #3
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.