• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:16
CEST 18:16
KST 01:16
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Reynor: GSL Loss Wasn't About Preparation Format12[IPSL] Spring 2026 Grand Finals - This Weekend!5Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Is the larve respawn broken? BGE Stara Zagora to be held again in June 2025 Weekly Cups (July 6 - 12): Protoss strike back Serral wins HomeStory Cup 29 Yamato Cup Series
Tourneys
WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29 Vespene Cup #1 — $300+ USD, July 10
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
Recommended FPV games (post-KeSPA) Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) BGH Auto Balance -> http://bghmmr.eu/ Etiquete rules in Asl? screpdb: new Starcraft reporting tool
Tourneys
[IPSL] Spring 2026 Grand Finals - This Weekend! Escore Tournament - Season 3 [Megathread] Daily Proleagues [ASL22] Wildcard Qualifier
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
General RTS Discussion Thread Path of Exile Nintendo Switch Thread Stormgate/Frost Giant Megathread Summer Games Done Quick 2026!
Dota 2
Looking for a Dota Mentor 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
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread UK Politics Mega-thread YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Movie Discussion! Series you have seen recently...
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Tennis[sport] Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
Gauntlet SC2: A Retrospectiv…
Ctone23
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 6555 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
Germany2596 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
Next event in 44m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 298
Harstem 123
UpATreeSC 35
StarCraft: Brood War
Calm 8323
Sea 1799
Britney 1334
Soma 805
EffOrt 722
Light 591
Mini 509
BeSt 365
Larva 228
Snow 223
[ Show more ]
actioN 196
Soulkey 185
Mong 118
Sharp 94
Sea.KH 57
Zeus 56
JYJ 49
Pusan 46
ggaemo 45
Free 38
Rush 35
sorry 34
soO 30
Terrorterran 30
scan(afreeca) 29
910 27
Killer 25
Sexy 17
Bale 14
IntoTheRainbow 11
zelot 10
Sacsri 9
ajuk12(nOOB) 8
Dota 2
Gorgc8409
qojqva1130
Trikslyr55
Counter-Strike
fl0m1379
x6flipin756
kRYSTAL_303
allub256
Super Smash Bros
C9.Mang028
Other Games
singsing1662
Liquid`RaSZi806
ceh9804
B2W.Neo451
ToD195
XaKoH 141
KnowMe99
QueenE82
Rex12
Organizations
Other Games
gamesdonequick2545
StarCraft 2
TaKeTV292
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 85
• LUISG 7
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis2104
Other Games
• Shiphtur286
Upcoming Events
OSC
44m
MaxPax vs Solar
ByuN vs Cure
Shameless vs Lambo
SKillous vs Cham
Percival vs Harstem
ShoWTimE vs Krystianer
Replay Cast
16h 44m
CrankTV Team League
18h 44m
WardiTV Qualifier
19h 44m
Epic.LAN
20h 44m
Replay Cast
1d 7h
RSL Revival
1d 16h
Clem vs Lambo
Scarlett vs Cure
CranKy Ducklings
1d 17h
Epic.LAN
1d 20h
IPSL
1d 23h
Dragon vs Hawk
[ Show More ]
RSL Revival
2 days
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
2 days
IPSL
2 days
Bonyth vs Ret
WardiTV Weekly
3 days
Monday Night Weeklies
3 days
PiGosaur Cup
5 days
The PondCast
5 days
Replay Cast
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Proleague 2026-07-13
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026

Upcoming

Escore Tournament S3: W3
ASL S22 SEASON OPEN Day 1
Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
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.