• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:52
CEST 15:52
KST 22:52
  • 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
[ASL21] Ro24 Preview Pt2: News Flash8[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy15ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book20
Community News
Weekly Cups (March 23-29): herO takes triple6Aligulac acquired by REPLAYMAN.com/Stego Research7Weekly Cups (March 16-22): herO doubles, Cure surprises3Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool49Weekly Cups (March 9-15): herO, Clem, ByuN win4
StarCraft 2
General
Team Liquid Map Contest #22 - Presented by Monster Energy Aligulac acquired by REPLAYMAN.com/Stego Research Weekly Cups (March 23-29): herO takes triple What mix of new & old maps do you want in the next ladder pool? (SC2) herO wins SC2 All-Star Invitational
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament RSL Season 4 announced for March-April StarCraft Evolution League (SC Evo Biweekly) WardiTV Mondays World University TeamLeague (500$+) | Signups Open
Strategy
Custom Maps
[M] (2) Frigid Storage Publishing has been re-enabled! [Feb 24th 2026]
External Content
Mutation # 519 Inner Power The PondCast: SC2 News & Results Mutation # 518 Radiation Zone Mutation # 517 Distant Threat
Brood War
General
ASL21 General Discussion A cwal.gg Extension - Easily keep track of anyone Behind the scenes footage of ASL21 Group E BW General Discussion BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL21] Ro24 Group E 🌍 Weekly Foreign Showmatches [ASL21] Ro24 Group F Azhi's Colosseum - Foreign KCM
Strategy
Fighting Spirit mining rates What's the deal with APM & what's its true value Simple Questions, Simple Answers
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Starcraft Tabletop Miniature Game General RTS Discussion Thread Darkest Dungeon
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
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 Five o'clock TL Mafia
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine The Games Industry And ATVI European Politico-economics QA Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion Cricket [SPORT] Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1873 users

The Big Programming Thread - Page 215

Forum Index > General Forum
Post a Reply
Prev 1 213 214 215 216 217 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.
lonelyPotato
Profile Joined December 2012
Australia158 Posts
December 11 2012 10:11 GMT
#4281
On December 11 2012 19:07 Tobberoth wrote:
Show nested quote +
On December 11 2012 18:58 lonelyPotato wrote:
On December 11 2012 18:55 Tobberoth wrote:
On December 11 2012 18:53 lonelyPotato wrote:
On December 11 2012 18:50 tec27 wrote:
On December 11 2012 18:45 Tobberoth wrote:
On December 11 2012 18:31 Coal wrote:
Hello! I just started playing around with HTML for fun (I intend to learn how to create simpler websites one day), and I have a question. Since I just started, should I learn HTML or HTML 5? What are the differences between the two?


HTML5 and HTML is the same thing. HTML5 is just the most recent version of HTML, what you mean is probably HTML4 which is old. The differences are usually pretty minor, HTML5 just have some extra tags to work with. Obviously, there are huge differences in the background though.

You should definitely learn HTML5, everything else is outdated, including XHTML.

This. 100%.

lonelyPotato, please don't give advice about things you don't understand.

HTML5 does include some features/tags that aren't currently well supported in all browsers, but these are mostly extravagant things. For basic tags, all modern browsers will support them just fine. If you do get into learning about the more advanced stuff, this site: http://caniuse.com/ is really useful for figuring out which browsers support what.


I don't really know what I said wrong?

Basically, recommending someone to learn HTML4 over HTML5 is like telling someone who wants to learn photoshop that it's better to learn it using Photoshop CS3 over using CS5. It really makes no sense why you would want to learn using an old outdated version of something. It's not like HTML5 is more complicated, anything written in HTML4 can be rewritten to HTML5 and will look better in the process, such as the new Doctype etc.


True, you didn't have to say I didn't know what I was talking about though. I stated the difference between the languages and what I found different.

Honestly, HTML 4 elements were for me easier to use, and if you want to get a solid understanding of Web based programming you should have a solid understanding of both of the versions elements, especially since so many people still are using HTML 4.

I never said you didn't know what you were talking about, I agree with the person saying you gave bad advice though. I don't see how HTML4 elements can be easier to use, HTML5 uses the exact same elements, the only difference is that you can add in extra elements if you want, such as <section>, <header> and <footer>. If you have any idea how tags work, which you should obviously learn if you learn HTML, you realize that that these tags, all tags, are extremely simple. Outside of CSS usage, it's just basic semantics. "I want my email in the footer of the website, maybe I should add it in a <footer> element at the bottom so I can later style it". Perfect. You can put it in a div in HTML4 for the same reason if you find that simpler for some reason, but nothing stops you from doing that in HTML5 if the <footer> tag scares you.

As for a lot of people using HTML4, that's true. A lot of people still use outdated versions of Internet Explorer. Just because other people are dumb and ignorant doesn't mean it's a good idea to go that route yourself.


It's nothing to do with being dumb, it's to do with cost and minimizing web disruptions. I won't put it up at the level of IPv6 in terms of disruptions, but it's partially a similar reason why people won't switch to that.

They go by the theory, why fix something that aint broke.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
December 11 2012 10:15 GMT
#4282
On December 11 2012 19:11 lonelyPotato wrote:
Show nested quote +
On December 11 2012 19:07 Tobberoth wrote:
On December 11 2012 18:58 lonelyPotato wrote:
On December 11 2012 18:55 Tobberoth wrote:
On December 11 2012 18:53 lonelyPotato wrote:
On December 11 2012 18:50 tec27 wrote:
On December 11 2012 18:45 Tobberoth wrote:
On December 11 2012 18:31 Coal wrote:
Hello! I just started playing around with HTML for fun (I intend to learn how to create simpler websites one day), and I have a question. Since I just started, should I learn HTML or HTML 5? What are the differences between the two?


HTML5 and HTML is the same thing. HTML5 is just the most recent version of HTML, what you mean is probably HTML4 which is old. The differences are usually pretty minor, HTML5 just have some extra tags to work with. Obviously, there are huge differences in the background though.

You should definitely learn HTML5, everything else is outdated, including XHTML.

This. 100%.

lonelyPotato, please don't give advice about things you don't understand.

HTML5 does include some features/tags that aren't currently well supported in all browsers, but these are mostly extravagant things. For basic tags, all modern browsers will support them just fine. If you do get into learning about the more advanced stuff, this site: http://caniuse.com/ is really useful for figuring out which browsers support what.


I don't really know what I said wrong?

Basically, recommending someone to learn HTML4 over HTML5 is like telling someone who wants to learn photoshop that it's better to learn it using Photoshop CS3 over using CS5. It really makes no sense why you would want to learn using an old outdated version of something. It's not like HTML5 is more complicated, anything written in HTML4 can be rewritten to HTML5 and will look better in the process, such as the new Doctype etc.


True, you didn't have to say I didn't know what I was talking about though. I stated the difference between the languages and what I found different.

Honestly, HTML 4 elements were for me easier to use, and if you want to get a solid understanding of Web based programming you should have a solid understanding of both of the versions elements, especially since so many people still are using HTML 4.

I never said you didn't know what you were talking about, I agree with the person saying you gave bad advice though. I don't see how HTML4 elements can be easier to use, HTML5 uses the exact same elements, the only difference is that you can add in extra elements if you want, such as <section>, <header> and <footer>. If you have any idea how tags work, which you should obviously learn if you learn HTML, you realize that that these tags, all tags, are extremely simple. Outside of CSS usage, it's just basic semantics. "I want my email in the footer of the website, maybe I should add it in a <footer> element at the bottom so I can later style it". Perfect. You can put it in a div in HTML4 for the same reason if you find that simpler for some reason, but nothing stops you from doing that in HTML5 if the <footer> tag scares you.

As for a lot of people using HTML4, that's true. A lot of people still use outdated versions of Internet Explorer. Just because other people are dumb and ignorant doesn't mean it's a good idea to go that route yourself.


It's nothing to do with being dumb, it's to do with cost and minimizing web disruptions. I won't put it up at the level of IPv6 in terms of disruptions, but it's partially a similar reason why people won't switch to that.

They go by the theory, why fix something that aint broke.

It's one thing not to fix something old which works, and another to build something new in something old when a superior new version exists. If you have a 5 year old complex webpage using HTML4, you're obviously not going to force a rewrite to HTML5, I sure as hell don't do it at my job. If you're LEARNING HTML though, there's literally no reason what so ever to learn HTML4 over HTML5. Especially since you'll have no problem working with old HTML4 pages just because you happen to know HTML5.
lonelyPotato
Profile Joined December 2012
Australia158 Posts
December 11 2012 10:16 GMT
#4283
On December 11 2012 19:08 AmericanUmlaut wrote:
Show nested quote +
On December 11 2012 19:00 lonelyPotato wrote:
On December 11 2012 18:56 AmericanUmlaut wrote:
On December 11 2012 18:43 lonelyPotato wrote:
On December 11 2012 18:31 Coal wrote:
Hello! I just started playing around with HTML for fun (I intend to learn how to create simpler websites one day), and I have a question. Since I just started, should I learn HTML or HTML 5? What are the differences between the two?



HTML 5 offers better error handling (Corporations used to have to reverse engineer through HTML 4 code, that's not as much of an issue any more), better defined semantics (Basically means your code becomes a lot more organized), and also has lots of small little added features that allow for a more dynamic feel to your website rather than having to use little third party programs to do so.

I am not a professional with HTML, but I have done a course for it at university, and personally I find HTML4 easier to use than HTML 5. So for a learning platform, I would learn HTML 4 first, and if you like what you see, you can make the jump to HTML 5 with ease if you have a solid understanding of HTML 4.

If you want more information then don't be afraid to ask.

Almost nothing you said in this post is accurate or useful.


Wait are you serious! HTML doesn't offer better defined semantics? Are you really saying that is wrong?

Are you saying that HTML 4 Wasn't retardedly hard to reverse engineer relative to that of HTML 5?

Are you saying that HTML 5 doesn't offer a more dynamic feel without having to access third party programs?

How is any of what I said wrong?

How does HTML 5 offer better error handling? HTML is a markup language: it has no error handling.

What do you mean by "reverse engineering"? You don't have to reverse engineer anything in HTML. Reverse engineering means looking at a result and then creating a system to generate that result, that doesn't even make sense as something that you would do in the context of HTML, which is served in plain text - if you want to know how a result is generated, you read the served markup.

How is HTML4 "easier to use" than HTML5? HTML5 is basically a superset of HTML4, so you're saying it's easier to learn a subset of a language's features, but that's self-evident, and the way you write it implies that writing markup to generate a result in HTML4 is simpler than writing markup to generate the same result in HTML5, which is absurd because HTML4 markup works in an HTML5-compliant browser.

Edited: For niceness and grammar.

Also: I do agree that HTML5's additional tags make markup more semantic.


I was referring to the new Parsing/Compatibility rules when it comes to error handling.
Kiante
Profile Blog Joined December 2009
Australia7069 Posts
December 11 2012 10:38 GMT
#4284
Hey lonelypotato do you live in brisbane>?
Writer
lonelyPotato
Profile Joined December 2012
Australia158 Posts
December 11 2012 10:58 GMT
#4285
On December 11 2012 19:38 Kiante wrote:
Hey lonelypotato do you live in brisbane>?


Nah Adelaide.
Coal
Profile Joined July 2011
Sweden1535 Posts
December 11 2012 11:05 GMT
#4286
Thank you for all the answers! I'm sure lonelypotato meant no harm I'll check in later if I have any questions!
In order to succeed, your desire for success should be greater than your fear of failure.
carlfish
Profile Joined June 2011
Australia57 Posts
Last Edited: 2012-12-11 11:44:40
December 11 2012 11:42 GMT
#4287
On December 11 2012 19:08 AmericanUmlaut wrote:
How does HTML 5 offer better error handling? HTML is a markup language: it has no error handling.


One of the practical problems with HTML4 was that it did not provide a clear definition of what a user-agent should do when it encountered bad markup.

Ideally this wouldn't be a problem because all markup would be valid, but in the real world "tag soup" is the norm. When a browser encountered something broken like <i><b>hello</i></b>, the behaviour would be undefined. Most browsers would internally convert the above into _some_ kind of valid DOM so the markup could be displayed in the browser, but there as no guarantee that each browser would produce the same DOM.

This would cause problems because CSS and Javascript rely on DOM selectors to function, and if two browsers are producing different internal DOMs for the same (invalid) markup, then that would mean the webpage would display differently in different browsers. A bad thing. You could argue until you were blue in the face that web authors should just fix their markup, but the practical result for the browser vendor was that end-users would complain that their browser "didn't show pages properly" compared to whatever browser the site had been developed for.

Often, browsers would waste a lot of time trying to reverse-engineer what other browsers were doing with bad markup in an effort to remain bug-for-bug compatible and thus display real-world web pages in the same way as their more popular competitors.

HTML5 recognised this problem, and the spec goes to great lengths to define what browsers should do when they encounter bad markup, and especially what they should do while parsing to turn bad markup into good, predictable DOM.
I am a fish.
mcc
Profile Joined October 2010
Czech Republic4646 Posts
December 11 2012 12:11 GMT
#4288
On December 11 2012 17:56 Poopi wrote:
Thanks for the info guys. I will definitively use it if I ever put something on the internet using PHP/MySQL, however I forgot to precise that it was a school project which I send in .zip and will be tested in local. Thus protecting properly isn't really necessary since well, the only person who will see this will have access to every file anyways.

However we were told about security, but only about mysql_real_escape_string so I did use it even though in this case it's pointless we had to do this at least.

By the way for these type of SQL injects, the "malicious" user (lol) has to know or guess your table names, hasn't he?

You should still make it a habit to use parameters anyway. Good habits are half of programming Plus it actually should make the queries more effective.
AmericanUmlaut
Profile Blog Joined November 2010
Germany2594 Posts
December 11 2012 12:35 GMT
#4289
On December 11 2012 20:42 carlfish wrote:
Show nested quote +
On December 11 2012 19:08 AmericanUmlaut wrote:
How does HTML 5 offer better error handling? HTML is a markup language: it has no error handling.


One of the practical problems with HTML4 was that it did not provide a clear definition of what a user-agent should do when it encountered bad markup.

Ideally this wouldn't be a problem because all markup would be valid, but in the real world "tag soup" is the norm. When a browser encountered something broken like <i><b>hello</i></b>, the behaviour would be undefined. Most browsers would internally convert the above into _some_ kind of valid DOM so the markup could be displayed in the browser, but there as no guarantee that each browser would produce the same DOM.

This would cause problems because CSS and Javascript rely on DOM selectors to function, and if two browsers are producing different internal DOMs for the same (invalid) markup, then that would mean the webpage would display differently in different browsers. A bad thing. You could argue until you were blue in the face that web authors should just fix their markup, but the practical result for the browser vendor was that end-users would complain that their browser "didn't show pages properly" compared to whatever browser the site had been developed for.

Often, browsers would waste a lot of time trying to reverse-engineer what other browsers were doing with bad markup in an effort to remain bug-for-bug compatible and thus display real-world web pages in the same way as their more popular competitors.

HTML5 recognised this problem, and the spec goes to great lengths to define what browsers should do when they encounter bad markup, and especially what they should do while parsing to turn bad markup into good, predictable DOM.

That's true, but it's a user-agent feature, not an aspect of the language itself. It makes the lives of browser developers better, because they don't have to figure out what the de facto industry standard is for being liberal in accepting mangled markup, but it basically has no impact on a developer. It just means that your mangled markup, whether you were trying to write HTML4 or HTML5, will look more consistent across browsers.
The frumious Bandersnatch
3FFA
Profile Blog Joined February 2010
United States3931 Posts
Last Edited: 2012-12-11 21:43:59
December 11 2012 21:35 GMT
#4290
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

Some things my teacher loves to give us is questions that have us:
1) Correct a program and/or rewrite it
2) Find what 1 error is in a program
3) Find what the purpose of the program is (Example is that one she gave us and asked this question just skipped lines...)
4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2012-12-11 23:14:31
December 11 2012 21:49 GMT
#4291
On December 12 2012 06:35 3FFA wrote:
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

Some things my teacher loves to give us is questions that have us:
1) Correct a program and/or rewrite it
2) Find what 1 error is in a program
3) Find what the purpose of the program is (Example is that one she gave us and asked this question just skipped lines...)
4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)



1 and 2 are the same.

I'm just going to point out a common error question, semi-colons after a loop conditional, such as.
int i = 0;
for ( i = 0; i < n; i++ );
printf("%d",i);

versus
int i = 0;
for ( i = 0; i < n; i++ )
printf("%d",i);


Finding errors should really be fun on tests. Not so in real life.

You will need to differentiate between syntactic and semantic errors.

3. Purpose should be easily found by tracing, if you understand the code. It helps to write out what they're doing by hand. Verify you understand how <= versus < affects a condition.

The output of
int i = 0;
while ( i <= 10 ) i = i + 1;


is different from
int i = 0;
while ( i < 10 ) i = i + 1;


4. I think you mean factors? There's only 1 factorial of 10. These questions should just require rudimentary math knowledge. Try doing things like the Fibonacci sequence, FizzBuzz, or the 1000 Lockers problem with your computer. (Google)

Practice coding anything. That is literally all the heck you have to do to study a problem solving programming course.

http://www.reddit.com/r/dailyprogrammer/

will help get your started becoming confident in your programming skills. The current day's question tests file input and string comparison among other things. If you don't understand file input, you should understand and use stream redirection.

Otherwise, revisit your old assignment questions and rewrite them with different numbers or input, and make them better using what you know now.

Also, if it's not online, practice coding by hand.
There is no one like you in the universe.
3FFA
Profile Blog Joined February 2010
United States3931 Posts
December 11 2012 22:33 GMT
#4292
Ok thanks! That was better than I was expecting! This forum never fails to surprise me, and this thread never fails to impress me.
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
December 11 2012 23:22 GMT
#4293
On December 12 2012 06:49 Blisse wrote:
+ Show Spoiler +
On December 12 2012 06:35 3FFA wrote:
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

Some things my teacher loves to give us is questions that have us:
1) Correct a program and/or rewrite it
2) Find what 1 error is in a program
3) Find what the purpose of the program is (Example is that one she gave us and asked this question just skipped lines...)
4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)


1 and 2 are the same.

I'm just going to point out a common error question, semi-colons after a loop conditional, such as.
int i = 0;
for ( i = 0; i < n; i++ );
printf("%d",i);

versus
int i = 0;
for ( i = 0; i < n; i++ )
printf("%d",i);


Finding errors should fun on tests.

You need to differentiate between syntactic and semantic errors.

3. Purpose should be easily found by tracing, if you understand the code. It helps to write out stuff by hand. Verify you understand how <= versus < affects a condition.

The output of
int i = 0;
while ( i <= 10 ) i = i + 1;


is different from
int i = 0;
while ( i < 10 ) i = i + 1;


4. I think you mean factors? There's only 1 factorial of 10. That should just be rudimentary math knowledge. Try doing things like the Fibonacci sequence, FizzBuzz, or the 1000 Lockers problem with your computer. (Google)

Practice coding anything. That is literally all the heck you have to do to study a problem solving programming course.

http://www.reddit.com/r/dailyprogrammer/

will help get your started becoming confident in your programming skills. The current day's question tests file input and string comparison among other things. If you don't understand file input, you should understand and use stream redirection.

Otherwise, revisit your old assignment questions and rewrite them with different numbers or input, and make them better using what you know now.

Also, if it's not online, practice coding by hand.


Love this specific advice, bolded parts I think are worth stressing (I won't write too much more on this, since Blisse nailed it).
No one can tell you the best way for you to study or practice something. There isn't any secret towards practice, except to do something, and to enjoy doing something enough that you want to come back to it later.

It's ok for programming to make you feel frustrated. That's a sign that your brain is actively trying to figure something out, and it may never go away, as the problems you encounter when programming just get larger an more difficult to handle. What you should avoid is feeling bored. If you are feeling bored during studying, then go find a different way to study.

Here's some tunes to study to:
echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay
Any sufficiently advanced technology is indistinguishable from magic
magicmUnky
Profile Joined June 2011
Australia280 Posts
December 12 2012 00:14 GMT
#4294
I think he meant 1!, 2!, 3!, ... , 10!

1
2
6
24
etc etc

I'm working through a C++ book and another for writing for embedded systems... lots of fun! Someone on here advised me to purchase "C++ Primer 5th Ed - Lippman, Lajole, Moo" and I'm finding it really handy.. it's much more explanatory than my other books (Programming C, Matlab and Java for Engineers).

One thing I can't really wrap my head around is; why does cin use >> and cout use <<?

I know i can do things like std::cin >> var1 >> var2;
but why does cout demand <<? The book says it's because the cin command takes it's right operator as the statement but cout takes it's left hand operand or something along those lines.. confusing
thOr6136
Profile Blog Joined July 2009
Slovenia1775 Posts
December 12 2012 00:19 GMT
#4295
Yo guys i need your help!

So, basically lets say we have 2D array, for example height = 7 and width = 7. Next i choose an element in this array, lets say [2][3]. My task is to go to every element that is in horizontal, vertical and diagonal line and do something with it. Now here is my question, is there any other more efficient, less time-consuming way to go through these elements other then making basically 8 loops (one for up, down, left right, up-left, up-right... etc.)?
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2012-12-12 00:38:19
December 12 2012 00:36 GMT
#4296
On December 12 2012 09:14 magicmUnky wrote:
I think he meant 1!, 2!, 3!, ... , 10!

1
2
6
24
etc etc

I'm working through a C++ book and another for writing for embedded systems... lots of fun! Someone on here advised me to purchase "C++ Primer 5th Ed - Lippman, Lajole, Moo" and I'm finding it really handy.. it's much more explanatory than my other books (Programming C, Matlab and Java for Engineers).

One thing I can't really wrap my head around is; why does cin use >> and cout use <<?

I know i can do things like std::cin >> var1 >> var2;
but why does cout demand <<? The book says it's because the cin command takes it's right operator as the statement but cout takes it's left hand operand or something along those lines.. confusing


Oof, let's start with the lingo. C++ uses these operators as 'stream operators'. The '<<' version is an 'insertion operator'. Putting some bits into a 'stream' can be rather confusing on the low level side of things, so C++ uses this operator with output streams to format the stream to the right, and make a call to sprint(STD_OUT,"**formatted stuff**"), which will push the bits through to the standard out stream (usually your terminal, for embedded projects, its normally the UART0 or SPI port, depending on the board/libraries you are using).

the '>>' operator is used as the 'extraction operator', which then pulls bits off the stream (when they are available) and formats it to fit the right side.

They are both 'overloaded operators' brought in from the <iostream.h> library to make streams easier to use. Overloading an operator just means defining it to use it for a different set of types. For example, you could overload '+' to work for a Vector class (Vector::operator+), then in the definition, make it so when you add two vectors, Vector A and Vector B, it does it the intuitive way.

EDIT: also, cout and cin are referred to as 'streams', which really just means its a file descriptor. Network sockets are streams as well. There are other streams too, but the definition is different system to system.
Any sufficiently advanced technology is indistinguishable from magic
HaRuHi
Profile Blog Joined November 2010
1220 Posts
December 12 2012 00:44 GMT
#4297
On December 12 2012 09:14 magicmUnky wrote:
I know i can do things like std::cin >> var1 >> var2;
but why does cout demand <<? The book says it's because the cin command takes it's right operator as the statement but cout takes it's left hand operand or something along those lines.. confusing


The Idea behind designing it like this was:

cin is a stream,
an input stream.
a stream flows,
with "cin>>var1" ,cin flows into var1.

cout aswell is a stream,
with "cout<<var1",
var1 flows into the outputstream.

Donnu if that is helpful for remembering when to why use what^^.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
December 12 2012 00:59 GMT
#4298
On December 12 2012 09:19 thOr6136 wrote:
Yo guys i need your help!

So, basically lets say we have 2D array, for example height = 7 and width = 7. Next i choose an element in this array, lets say [2][3]. My task is to go to every element that is in horizontal, vertical and diagonal line and do something with it. Now here is my question, is there any other more efficient, less time-consuming way to go through these elements other then making basically 8 loops (one for up, down, left right, up-left, up-right... etc.)?


psuedocode, assuming a square matrix, deal with it:

Given you start at X,Y ---
for(i:0->MATRIX WIDTH)
{
matrix[Y][i] //horizontal row
matrix[i][X] //vertical column
matrix[Y+i][X+i] //down and to the right
matrix[Y-i][X+i] //up and to the right
matrix[Y+i][X-i] //down and to the left
matrix[Y-i][X+i] //up and to the left
}


Left intentionally unoptimized. This should give you the right idea of how to traverse matrices.

For a bit of math to get you started, you will need a maximum of 2 for loops to do most matrix problems. If you can find no other way, traverse the entire matrix, and check if the spot you are at is the one you are looking for using your math equations you calculated:


for(i:0->MAX_X)
for(j:0->MAX_Y)
if(j==Y) //horizontal row
if(X+i==Y+j) //diagonal
and so on..


The single for loop example above is a reduction of this complete case
Any sufficiently advanced technology is indistinguishable from magic
adwodon
Profile Blog Joined September 2010
United Kingdom592 Posts
December 12 2012 09:31 GMT
#4299
On December 12 2012 06:49 Blisse wrote:
Show nested quote +
On December 12 2012 06:35 3FFA wrote:
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)



4. I think you mean factors? There's only 1 factorial of 10. These questions should just require rudimentary math knowledge. Try doing things like the Fibonacci sequence, FizzBuzz, or the 1000 Lockers problem with your computer. (Google)

Practice coding anything. That is literally all the heck you have to do to study a problem solving programming course.

http://www.reddit.com/r/dailyprogrammer/

will help get your started becoming confident in your programming skills. The current day's question tests file input and string comparison among other things. If you don't understand file input, you should understand and use stream redirection.

Otherwise, revisit your old assignment questions and rewrite them with different numbers or input, and make them better using what you know now.

Also, if it's not online, practice coding by hand.


http://projecteuler.net/ is great for those relatively quick, self contained programming problems.

Some are really tricky and may take a little while but they're all perfectly doable by 1 person at a reasonable pace, try doing one or two a week and you'll really improve. It's also a good way to learn new languages, trying to redo old problems in a new language can help you get a grip on it a bit better.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2012-12-12 16:14:45
December 12 2012 15:59 GMT
#4300
On December 12 2012 18:31 adwodon wrote:
Show nested quote +
On December 12 2012 06:49 Blisse wrote:
On December 12 2012 06:35 3FFA wrote:
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)



4. I think you mean factors? There's only 1 factorial of 10. These questions should just require rudimentary math knowledge. Try doing things like the Fibonacci sequence, FizzBuzz, or the 1000 Lockers problem with your computer. (Google)

Practice coding anything. That is literally all the heck you have to do to study a problem solving programming course.

http://www.reddit.com/r/dailyprogrammer/

will help get your started becoming confident in your programming skills. The current day's question tests file input and string comparison among other things. If you don't understand file input, you should understand and use stream redirection.

Otherwise, revisit your old assignment questions and rewrite them with different numbers or input, and make them better using what you know now.

Also, if it's not online, practice coding by hand.


http://projecteuler.net/ is great for those relatively quick, self contained programming problems.

Some are really tricky and may take a little while but they're all perfectly doable by 1 person at a reasonable pace, try doing one or two a week and you'll really improve. It's also a good way to learn new languages, trying to redo old problems in a new language can help you get a grip on it a bit better.


I'm less a fan of Project Euler because it only focuses on mathematical problem solving. DailyProgrammer puts out a mix of mathematical problem solving, and also other stuff like string manipulation and fun things like Pokemon type comparisons, which can involve a lot more than just hard coding some numbers together.


On December 12 2012 09:14 magicmUnky wrote:
I think he meant 1!, 2!, 3!, ... , 10!

1
2
6
24
etc etc

I'm working through a C++ book and another for writing for embedded systems... lots of fun! Someone on here advised me to purchase "C++ Primer 5th Ed - Lippman, Lajole, Moo" and I'm finding it really handy.. it's much more explanatory than my other books (Programming C, Matlab and Java for Engineers).

One thing I can't really wrap my head around is; why does cin use >> and cout use <<?

I know i can do things like std::cin >> var1 >> var2;
but why does cout demand <<? The book says it's because the cin command takes it's right operator as the statement but cout takes it's left hand operand or something along those lines.. confusing



>> is an extraction operator. http://www.cplusplus.com/reference/istream/istream/operator>>/

<< is an insertion operator. http://www.cplusplus.com/reference/ostream/ostream/operator<</

What does that mean?

When you do,

std::cin >> var;


you are performing an extraction out of the std::cin stream, which is your standard input.

When you do,

std::cout << word << std::endl;


you are performing an insertion of your word into the std::cout stream, which is your standard output.


Why don't they combine the two? Because overloading functions like you want would confuse meaning of the words. It is much more clear to see in the

std::cin >> var;
std::cout << word << std::endl;


case, that the values from the stream std::cin are extracted into the value var, and the word is being inserted into the stream std::cout.

var << std::cin;
std::cout << var;


would look very strange, because now it's not clear what you're doing exactly. You overload the meaning of << as both an insertion operation and an extraction operation. However, it doesn't make sense to do that because the two operations are not associative. The + operator is associative in the sense that 1 + 2 == 2 + 1. It's an operation of add regardless. However, std::cin << word != word << std::cin, because they're both not insertion operations.

The << and >> separate the meaning of insertion and extraction.

I hope that makes some sense. I didn't design the language, but this is what seems to make sense for me.
There is no one like you in the universe.
Prev 1 213 214 215 216 217 1032 Next
Please log in or register to reply.
Live Events Refresh
WardiTV Team League
12:45
Group B
WardiTV532
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 213
SortOf 143
ProTech121
StarCraft: Brood War
Calm 7204
Bisu 3185
Sea 2543
Horang2 1830
Shuttle 946
EffOrt 944
Hyuk 831
Mini 665
Soma 570
Stork 508
[ Show more ]
firebathero 444
actioN 358
ggaemo 296
Rush 293
Snow 268
Soulkey 188
PianO 146
hero 139
sorry 82
Barracks 59
Sea.KH 59
Hyun 55
[sc1f]eonzerg 55
Backho 49
Aegong 37
zelot 33
Shinee 28
Movie 23
Hm[arnc] 22
910 22
Terrorterran 18
scan(afreeca) 14
Rock 12
IntoTheRainbow 12
ajuk12(nOOB) 12
soO 8
Dota 2
Gorgc6336
BananaSlamJamma602
canceldota113
Counter-Strike
x6flipin446
edward92
oskar48
Heroes of the Storm
XaKoH 146
Other Games
singsing1879
B2W.Neo1270
hiko526
crisheroes286
DeMusliM260
KnowMe114
RotterdaM111
ArmadaUGS92
Livibee54
QueenE49
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• iHatsuTV 7
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis2506
• Jankos2093
• TFBlade1133
Upcoming Events
OSC
10h 9m
RSL Revival
20h 9m
TriGGeR vs Cure
ByuN vs Rogue
Replay Cast
1d 10h
RSL Revival
1d 20h
Maru vs MaxPax
BSL
2 days
RSL Revival
2 days
uThermal 2v2 Circuit
3 days
BSL
3 days
Afreeca Starleague
3 days
Replay Cast
4 days
[ Show More ]
Sparkling Tuna Cup
4 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-03-31
WardiTV Winter 2026
NationLESS Cup

Ongoing

BSL Season 22
CSL Elite League 2026
CSL Season 20: Qualifier 1
ASL Season 21
CSL Season 20: Qualifier 2
RSL Revival: Season 4
Nations Cup 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

Escore Tournament S2: W1
CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
StarCraft2 Community Team League 2026 Spring
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 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.