• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 00:24
CET 06:24
KST 14:24
  • 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
Behind the Blue - Team Liquid History Book15Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8herO wins SC2 All-Star Invitational14
Community News
ACS replaced by "ASL Season Open" - Starts 21/0218LiuLi Cup: 2025 Grand Finals (Feb 10-16)23Weekly Cups (Feb 2-8): Classic, Solar, MaxPax win2Nexon's StarCraft game could be FPS, led by UMS maker10PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar)13
StarCraft 2
General
How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game? Nexon's StarCraft game could be FPS, led by UMS maker Terran Scanner Sweep Behind the Blue - Team Liquid History Book Weekly Cups (Jan 12-18): herO, MaxPax, Solar win
Tourneys
LiuLi Cup: 2025 Grand Finals (Feb 10-16) PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) RSL Revival: Season 4 Korea Qualifier (Feb 14) Sparkling Tuna Cup - Weekly Open Tournament RSL Season 4 announced for March-April
Strategy
Custom Maps
Map Editor closed ? [A] Starcraft Sound Mod
External Content
The PondCast: SC2 News & Results Mutation # 512 Overclocked Mutation # 511 Temple of Rebirth Mutation # 510 Safety Violation
Brood War
General
[ASL21] Potential Map Candidates Gypsy to Korea Which units you wish saw more use in the game? ACS replaced by "ASL Season Open" - Starts 21/02 Liquipedia.net NEEDS editors for Brood War
Tourneys
Escore Tournament StarCraft Season 1 [Megathread] Daily Proleagues Small VOD Thread 2.0 KCM Race Survival 2026 Season 1
Strategy
Fighting Spirit mining rates Zealot bombing is no longer popular? Simple Questions, Simple Answers Current Meta
Other Games
General Games
Path of Exile Diablo 2 thread Nintendo Switch Thread Battle Aces/David Kim RTS Megathread ZeroSpace Megathread
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 Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Ask and answer stupid questions here! European Politico-economics QA Mega-thread The Games Industry And ATVI Russo-Ukrainian War Thread
Fan Clubs
The IdrA Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
ADHD And Gaming Addiction…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1539 users

The Big Programming Thread - Page 153

Forum Index > General Forum
Post a Reply
Prev 1 151 152 153 154 155 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.
SiPa
Profile Joined July 2010
Germany129 Posts
Last Edited: 2012-08-01 11:39:46
August 01 2012 11:35 GMT
#3041
Doublepost, nvm.. pls delete
OPman
Profile Joined December 2010
United States131 Posts
Last Edited: 2012-08-01 14:13:46
August 01 2012 14:12 GMT
#3042
I've been going through the Hands-on Python Tutorial (which is fantastic by the way) and i'm having trouble with one of the exercises. The gist of the exercise is to ask the user for input asking for a file to open, copy the contents, and write them to a new file with the characters in all uppercase. The new filename would be the same as the old one, but with "UPPER" preceding it. The last bit is the only part I can't figure out.

Here's what I have so far.

filename = input('What file would you like to make an UPPER file for? ')
sheit = open(filename, 'r')
contents = sheit.read()

newfile = open('UPPER'filename, 'w') \\WTFSyntax
newfile.write(contents.upper())
filename.close()
newfile.close()


The 'UPPER' filename syntax is wrong, but I don't know the proper way to write it. Damn the site for not providing solutions >.<
Ph'nglui Mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn.
xlep
Profile Joined December 2009
Germany274 Posts
Last Edited: 2012-08-01 14:20:56
August 01 2012 14:19 GMT
#3043
never leaned python but google says: filename.upper() should work for ASCII strings
skill is scissors beating rock
OPman
Profile Joined December 2010
United States131 Posts
August 01 2012 14:30 GMT
#3044
On August 01 2012 23:19 xlep wrote:
never leaned python but google says: filename.upper() should work for ASCII strings


That works for making the filename FILENAME, I need to add the word "UPPER" before the filename and I think I figured that part out although the contents aren't being copied properly.

I changed this line here, and successfully made the new file, but the uppercase contents aren't copied over to it.

newfile = open("UPPER"+filename, 'w')


The error I'm getting in the Shell is saying: 'str' object has no attibute 'close' referring to filename.
Ph'nglui Mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn.
OPman
Profile Joined December 2010
United States131 Posts
August 01 2012 14:35 GMT
#3045
Fixed -_-

Rather than filename.close(), I should have written sheit.close(). Since the file wasn't ever closed properly, it seems like the contents weren't actually saved to the new file.

[image loading]
Ph'nglui Mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn.
EruIluvatar
Profile Joined July 2011
Germany2 Posts
August 02 2012 03:09 GMT
#3046
Hello guys,
I'm attempting to learn C.
I've got the first version of K&R's "The C Programming Language" from 1978, when C wasn't even standardized by ANSI. I like the style of that book with the explanations and tasks after every block.

My problem: Sometimes I get confused, when i try to correct the outdated code examples in order to write valid code that is accepted by the current compilers without warnings and error messages.

Should I buy the second edition following the ANSI C standard from 1988 which is over twenty years old as well, despite it does not cover the newer standards or would it be better to buy an other book, that isn't published such a long time ago?
If you recommend the last alternative, please give me a suggestion for a book that you prefer (english or german)
Eru

ps. first post on TL - was only reading before
DumJumJmyWum
Profile Joined March 2011
United States75 Posts
August 02 2012 03:13 GMT
#3047
On August 02 2012 12:09 EruIluvatar wrote:
Hello guys,
I'm attempting to learn C.
I've got the first version of K&R's "The C Programming Language" from 1978, when C wasn't even standardized by ANSI. I like the style of that book with the explanations and tasks after every block.

My problem: Sometimes I get confused, when i try to correct the outdated code examples in order to write valid code that is accepted by the current compilers without warnings and error messages.

Should I buy the second edition following the ANSI C standard from 1988 which is over twenty years old as well, despite it does not cover the newer standards or would it be better to buy an other book, that isn't published such a long time ago?
If you recommend the last alternative, please give me a suggestion for a book that you prefer (english or german)
Eru

ps. first post on TL - was only reading before


I would probably get the second version as it's still used today as a reference. It's what I used for my OS class a couple years ago that served me well, so I think it should work just fine without too many problems.
thOr6136
Profile Blog Joined July 2009
Slovenia1775 Posts
Last Edited: 2012-08-03 11:05:58
August 03 2012 10:58 GMT
#3048
Ok guys i have a question regarding c++

There is a function called FindFirstFile() and let's say we search for all COM files in some directory. Now when function finds first COM file, it saves its information in WIN32_FIND_DATA structure , and here is a problem, how can i get name of the file that was found?

EDIT: by getting it i mean like using it further down the program, not a specific name of file, more like a variable of some sort, if you know what i mean

Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
August 03 2012 11:04 GMT
#3049
On August 03 2012 19:58 thOr6136 wrote:
Ok guys i have a question regarding c++

There is a function called FindFirstFile() and let's say we search for all COM files in some directory. Now when function finds first COM file, it saves its information in WIN32_FIND_DATA structure , and here is a problem, how can i get name of the file that was found?


From the documentation you linked it looks like a simple:


WIN32_FIND_DATA foo;
FindFirstFile(..., &foo);
printf("%s", foo.cFileName);
thOr6136
Profile Blog Joined July 2009
Slovenia1775 Posts
August 03 2012 11:07 GMT
#3050
ty sir , this documentation confuses me sometimes
SgtCoDFish
Profile Blog Joined July 2010
United Kingdom1520 Posts
August 03 2012 11:13 GMT
#3051
On August 02 2012 12:09 EruIluvatar wrote:
Hello guys,
I'm attempting to learn C.
I've got the first version of K&R's "The C Programming Language" from 1978, when C wasn't even standardized by ANSI. I like the style of that book with the explanations and tasks after every block.

My problem: Sometimes I get confused, when i try to correct the outdated code examples in order to write valid code that is accepted by the current compilers without warnings and error messages.

Should I buy the second edition following the ANSI C standard from 1988 which is over twenty years old as well, despite it does not cover the newer standards or would it be better to buy an other book, that isn't published such a long time ago?
If you recommend the last alternative, please give me a suggestion for a book that you prefer (english or german)
Eru

ps. first post on TL - was only reading before


The second edition should serve you very well if you want to learn from a book, since it follows the "C89" standard which is pretty commonly used even today. The newer standard "C99" still isn't too widely used for various reasons as far as I know although I don't do much work in C. That said, the changes added in C99 aren't too numerous and are worth knowing about; I'd say learn from the second edition book if that's where you want to start from, and then learn the C99 stuff from the internet.

I think that's all true, but as I said I don't use much C as I do most of my stuff in C++/Java, so sorry if I made any mistakes.
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
Last Edited: 2012-08-03 12:36:20
August 03 2012 12:13 GMT
#3052
+ Show Spoiler +
sample.lex

/*
*/

%{
#include <stdio.h>
#include "y.tab.h"
extern YYSTYPE yylval;
%}

%%
[()]* yylval=strdup(yytext); return STRING;
check return CHECK;
%%








sample.y

%{
#include <stdio.h>
#include <string.h>
#include <string.h>


#define YYSTYPE char *


void yyerror(const char *str)
{
fprintf(stderr,"error: %s\n",str);
}

int yywrap()
{
return 1;
}

main()
{
yyparse();
}


%}

%token STRING
%token CHECK

%%
commands: /* empty */
| commands command
;

command:
binary
;

binary:
CHECK string1
{

printf("\tSTRING is :%s\n",$2);
}
;

string1:
STRING
{
$$=$1;
}
;


can i ask for some help about flex and bison?
its actually homework but i just got stuck here =/ i want the program to accept a string and its reverse. like a palindrome.
ex. (())))((

but so far all i can do is just output the input string. =/ do you guys have any tips on how should i proceed?

EDIT: btw my production rules are

s -> (s(,
s -> )s),
s -> (blank) but i cannot somehow understand how to code it =/
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Craton
Profile Blog Joined December 2009
United States17276 Posts
Last Edited: 2012-08-04 02:14:30
August 04 2012 02:11 GMT
#3053
There seems like a better way to write this: http://sqlfiddle.com/#!4/51e32/3

It's possible that query's a result of these painkillers just being really good.

Execution Plan:
+ Show Spoiler +
[image loading]


This is just some little thing I've got running locally and my DB design is kinda mediocre because it suffices for how I use it, but it still seems there should be a "better" way.
twitch.tv/cratonz
supereddie
Profile Joined March 2011
Netherlands151 Posts
Last Edited: 2012-08-04 09:07:55
August 04 2012 09:04 GMT
#3054
You might want to add primary key on CHAMPION_ALIASES and SUMMONERS and then use foreign keys in MATCH_HISTORY.

The query itself looks fine to me. Maybe you can use inner joins for CHAMPION_ALIASES as well if you know they always exists and there always are 10.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
EruIluvatar
Profile Joined July 2011
Germany2 Posts
August 05 2012 15:12 GMT
#3055
@DumJumJmyWum and SgtCoDFish

Thank you for your responses. I will order the book in the next days.
Craton
Profile Blog Joined December 2009
United States17276 Posts
August 05 2012 21:23 GMT
#3056
On August 04 2012 18:04 supereddie wrote:
You might want to add primary key on CHAMPION_ALIASES and SUMMONERS and then use foreign keys in MATCH_HISTORY.

The query itself looks fine to me. Maybe you can use inner joins for CHAMPION_ALIASES as well if you know they always exists and there always are 10.

Can't do Inner joins because the fields can be null in MATCH_HISTORY.

It just seems really weird to do it with so many joins, but I guess it's just because of how I set things up.
twitch.tv/cratonz
tec27
Profile Blog Joined June 2004
United States3702 Posts
August 05 2012 22:04 GMT
#3057
On August 06 2012 06:23 Craton wrote:
Show nested quote +
On August 04 2012 18:04 supereddie wrote:
You might want to add primary key on CHAMPION_ALIASES and SUMMONERS and then use foreign keys in MATCH_HISTORY.

The query itself looks fine to me. Maybe you can use inner joins for CHAMPION_ALIASES as well if you know they always exists and there always are 10.

Can't do Inner joins because the fields can be null in MATCH_HISTORY.

It just seems really weird to do it with so many joins, but I guess it's just because of how I set things up.

Pretty necessary if you're going to normalize it out like that, I think. You could do it in 2 separate queries (query for all the aliases from match history, then build a list and do an IN ( alias1, alias2, ... , aliasN ) in the second query), but you wouldn't really be saving execution time. You would, however, gain the ability to cache the alias information separately from the database and match history, which is valuable.
Can you jam with the console cowboys in cyberspace?
JeanLuc
Profile Joined September 2010
Canada377 Posts
August 06 2012 05:01 GMT
#3058
Hi guys,

I was hoping people who are studying C/C++ could help me with this. I have come back to C++ from a long sojourn learning "easier" languages such as Java, C#. My understanding of C++ was never that great, but I find myself confused about a lot of stuff. In this bit of code I tried writing a version of the common join() function you see in a lot of languages: basically, you give an array of strings to join() and it returns a string of the concatenated elements separated by a delimiter. What I have here seems to work but I have a bunch of questions to ask:

+ Show Spoiler +

//join.cpp
#include "join.h"
#include <iostream>
#include <cstring>
using namespace std;

int main(){
char * arr[]={"Yo","Adrian!","I","Did","It!","said","Rocky"};
char delimiter=',';

const char * phrase=join(arr,delimiter,sizeof(arr)/sizeof(char *));
cout<<phrase<<endl;
if(phrase!=NULL)
delete [] phrase;

}

const char * join(char * arr[], char delimiter, int words){
char * str;
int len=0;
int a=0;
for(int i=0; i<words; i++){
len+=strlen(arr[i])+1;
}
str=new char[len];
for(int i=0; i<words; i++){
for(int j=0; j<strlen(arr[i]); j++){
str[a++]=arr[i][j];
}
if(i<(words-1)) str[a++]=delimiter;
}
str[a]='\0';
return str;
}


One thing I'm curious about is.. whether the memory allocation/deallocation in this is handled OKAY. Is there a way to determine the length of the array of char pointers within the function so I don't need to pass that as a parameter? Is it necessary that the function return a const char *?


And basically, if you're so inclined, please bash this code and tell me why its noob (somethign which I intuit it to be). Thanks for any help you can offer.
If you can't find it within yourself to stand up and tell the truth-- you don't deserve to wear that uniform
Craton
Profile Blog Joined December 2009
United States17276 Posts
Last Edited: 2012-08-06 08:40:55
August 06 2012 08:01 GMT
#3059
Another question using the same database from before.

In one of my views I'd like to have a column denoting "streaks," where a streak is defined consecutive wins or losses. What I'd like to do is basically take my list if games, sort it by MHID descending, and then have some kind of SQL that will say there have been X many of this result in a row.

MHID are entered in such a way that a higher number denotes a more recent game, but may not be consecutive.

My thought was that I could achieve this by some kind of CONNECT BY logic, but I can't figure it out (I seemingly keep getting infinite loops with the logic I've tried).

I also tried LEAD and LAG but couldn't quite get there.

End result would look something like this:

MHID -- RESULT -- STREAK
9 -- LOSS -- 1
8 -- WIN -- 3
6 -- WIN -- 2
1 -- WIN -- 1
twitch.tv/cratonz
Abductedonut
Profile Blog Joined December 2010
United States324 Posts
August 06 2012 09:12 GMT
#3060
On August 06 2012 14:01 JeanLuc wrote:
Hi guys,

I was hoping people who are studying C/C++ could help me with this. I have come back to C++ from a long sojourn learning "easier" languages such as Java, C#. My understanding of C++ was never that great, but I find myself confused about a lot of stuff. In this bit of code I tried writing a version of the common join() function you see in a lot of languages: basically, you give an array of strings to join() and it returns a string of the concatenated elements separated by a delimiter. What I have here seems to work but I have a bunch of questions to ask:

+ Show Spoiler +

//join.cpp
#include "join.h"
#include <iostream>
#include <cstring>
using namespace std;

int main(){
char * arr[]={"Yo","Adrian!","I","Did","It!","said","Rocky"};
char delimiter=',';

const char * phrase=join(arr,delimiter,sizeof(arr)/sizeof(char *));
cout<<phrase<<endl;
if(phrase!=NULL)
delete [] phrase;

}

const char * join(char * arr[], char delimiter, int words){
char * str;
int len=0;
int a=0;
for(int i=0; i<words; i++){
len+=strlen(arr[i])+1;
}
str=new char[len];
for(int i=0; i<words; i++){
for(int j=0; j<strlen(arr[i]); j++){
str[a++]=arr[i][j];
}
if(i<(words-1)) str[a++]=delimiter;
}
str[a]='\0';
return str;
}


One thing I'm curious about is.. whether the memory allocation/deallocation in this is handled OKAY. Is there a way to determine the length of the array of char pointers within the function so I don't need to pass that as a parameter? Is it necessary that the function return a const char *?


And basically, if you're so inclined, please bash this code and tell me why its noob (somethign which I intuit it to be). Thanks for any help you can offer.


Your code is fine, for the most part. Your memory alloc/dealloc is fine, although, why keep arr around?
Really memory alloc/dealloc depends on the program. But yeah, yours is fine.

To answer your question, no, there's no way to find the size of an array in the traditional way you do in Java/C#. Although, you can use some ghetto tricks like ALWAYS ending the last element of the array in a word or int or whatever and searching for that in your function to find the answer. That's just C/C++, man.

To answer whether or not you HAD to declare it const, the answer is no. Const just basically means that the compiler should not alter the value. So if you did something like:
join(arr,delimiter,sizeof(arr)/sizeof(char *))[1] = 'a';

It will give you a compiler error, saying you're writing to read-only. Whereas, declaring it as just a char could potentially lead to a crash if you fired that same code. But otherwise, not too much to worry about there.

Here's something to bash your code. Declaring arr as:
char *arr[]= {"Yo","Adrian!","I","Did","It!","said","Rocky",NULL};

Leads to a NULL pointer dereference which could potentially allow a hacker to control flow of execution in your program by Mapping address 0 to a pointer that points to a function of his choice. Alternatively, it can be used to crash your program. Not very good if it's a anti-virus

Happy Programming!
Prev 1 151 152 153 154 155 1032 Next
Please log in or register to reply.
Live Events Refresh
RSL Revival
03:00
S4 Americas Server Qualifier
CranKy Ducklings168
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft473
PiGStarcraft400
SortOf 104
StarCraft: Brood War
sorry 136
Leta 121
yabsab 92
Dota 2
monkeys_forever327
LuMiX1
League of Legends
JimRising 684
Super Smash Bros
C9.Mang0746
Mew2King192
Other Games
tarik_tv10626
summit1g9908
ToD66
ViBE61
ZombieGrub42
Organizations
Other Games
gamesdonequick990
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• Hupsaiya 97
• practicex 28
• iHatsuTV 4
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
StarCraft: Brood War
• Diggity5
• iopq 3
• sM.Zik 2
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Scarra2208
• Lourlo1028
• Stunt451
Upcoming Events
RSL Revival
2h 37m
LiuLi Cup
5h 37m
Cure vs Reynor
Clem vs Maru
Rogue vs TriGGeR
ByuN vs Serral
uThermal 2v2 Circuit
6h 37m
PSISTORM Gaming Misc
11h 32m
RSL Revival
12h 37m
AI Arena Tournament
14h 37m
Replay Cast
18h 37m
Sparkling Tuna Cup
1d 4h
LiuLi Cup
1d 5h
Ladder Legends
1d 12h
[ Show More ]
Replay Cast
1d 18h
Replay Cast
2 days
LiuLi Cup
2 days
Wardi Open
2 days
Monday Night Weeklies
2 days
OSC
2 days
WardiTV Winter Champion…
3 days
Replay Cast
4 days
WardiTV Winter Champion…
4 days
Replay Cast
4 days
PiG Sty Festival
5 days
The PondCast
5 days
KCM Race Survival
5 days
WardiTV Winter Champion…
5 days
Replay Cast
5 days
PiG Sty Festival
6 days
Epic.LAN
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Escore Tournament S1: W8
Rongyi Cup S3
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
LiuLi Cup: 2025 Grand Finals
Nations Cup 2026
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025

Upcoming

[S:21] ASL SEASON OPEN 1st Round
[S:21] ASL SEASON OPEN 1st Round Qualifier
[S:21] ASL SEASON OPEN 2nd Round
[S:21] ASL SEASON OPEN 2nd Round Qualifier
Acropolis #4
IPSL Spring 2026
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
WardiTV Winter 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
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.