• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:23
CEST 03:23
KST 10:23
  • 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
Maestros of the Game: Week 1/Play-in Preview9[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9
Community News
Weekly Cups (August 25-31): Clem's Last Straw?6Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris45Weekly Cups (Aug 11-17): MaxPax triples again!15Weekly Cups (Aug 4-10): MaxPax wins a triple6
StarCraft 2
General
#1: Maru - Greatest Players of All Time Weekly Cups (August 25-31): Clem's Last Straw? Maestros of the Game: Week 1/Play-in Preview Weekly Cups (Aug 11-17): MaxPax triples again! 2024/25 Off-Season Roster Moves
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris Monday Nights Weeklies LiuLi Cup - September 2025 Tournaments 🏆 GTL Season 2 – StarCraft II Team League $5,100+ SEL Season 2 Championship (SC: Evo)
Strategy
Custom Maps
External Content
Mutation # 489 Bannable Offense Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies
Brood War
General
Victoria gamers Starcraft at lower levels TvP ASL20 General Discussion BGH Auto Balance -> http://bghmmr.eu/ Pros React To: herO's Baffling Game
Tourneys
[ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined! Small VOD Thread 2.0 Cosmonarchy Pro Showmatches
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread General RTS Discussion Thread Nintendo Switch Thread Path of Exile Warcraft III: The Frozen Throne
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Russo-Ukrainian War Thread YouTube Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 766 users

The Big Programming Thread - Page 215

Forum Index > General Forum
Post a Reply
Prev 1 213 214 215 216 217 1031 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
Germany2577 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
SEL S2 Championship: Playoffs
CranKy Ducklings101
Liquipedia
BSL Team Wars
21:30
Round 5
Team Dewalt vs Team Sziky
ZZZero.O44
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SpeCial 206
WinterStarcraft89
Nina 58
ProTech56
Ketroc 52
CosmosSc2 51
StarCraft: Brood War
Artosis 929
Shuttle 781
sSak 505
Aegong 59
ZZZero.O 44
Sharp 40
ajuk12(nOOB) 13
Dota 2
monkeys_forever416
NeuroSwarm79
LuMiX0
Super Smash Bros
hungrybox420
AZ_Axe133
Other Games
tarik_tv10771
summit1g9542
shahzam865
C9.Mang0461
JimRising 400
Day[9].tv227
Maynarde157
Sick152
Mew2King58
Livibee56
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota22436
Other Games
• Scarra792
• Day9tv227
Upcoming Events
Sparkling Tuna Cup
8h 37m
PiGosaur Monday
22h 37m
LiuLi Cup
1d 9h
Replay Cast
1d 22h
The PondCast
2 days
RSL Revival
2 days
Maru vs SHIN
MaNa vs MaxPax
OSC
3 days
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
3 days
Reynor vs Astrea
Classic vs sOs
BSL Team Wars
3 days
Team Bonyth vs Team Dewalt
CranKy Ducklings
4 days
[ Show More ]
RSL Revival
4 days
GuMiho vs Cham
ByuN vs TriGGeR
Cosmonarchy
4 days
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
[BSL 2025] Weekly
4 days
RSL Revival
5 days
Cure vs Bunny
Creator vs Zoun
BSL Team Wars
5 days
Team Hawk vs Team Sziky
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

CSL Season 18: Qualifier 2
SEL Season 2 Championship
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL 2025 AUTUMN (S18)
Maestros of the Game
Sisters' Call Cup
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

LASL Season 20
2025 Chongqing Offline CUP
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
EC S1
BLAST Rivals Fall 2025
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
MESA Nomadic Masters Fall
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
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 © 2025 TLnet. All Rights Reserved.