Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > Other Topics > Programming

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 04-10-2012, 12:49 PM   #16
Carpal \'Tunnel
 
clowntable's Avatar
 
Join Date: Jun 2006
Location: 39, 46, 56, 59, 191
Posts: 39,784
Re: Any C experts out there

Yeah if you want to learn all 3 I think it's best to actually start with C# (I'd obviously recommend Python or Ruby but C# is fine as well). Some people disagree but I think higher level languages are the better gateway languages.

Understand higher level concepts (control flow, data structures, OOP stuff) first then improve your "craft" for lack of a better word (make code look nicer, get better at testing/TDD/BDD) and then you can fiddle with bits and try to avoid buffer overflows :P

Edit: Just saw your comment. If you just want to get familiar with what working small programs look like I think you should write FizzBuzz in all three languages. Move on to the next language once you have a working FizzBuzz in the first (you're almost there in C FWIW). Then after you've done all three you can decide what language you want to move on in.

Quote:
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
http://www.codinghorror.com/blog/200...s-program.html
clowntable is offline   Reply With Quote
Old 04-10-2012, 12:50 PM   #17
centurion
 
Join Date: Dec 2011
Location: Cloud 9
Posts: 145
Re: Any C experts out there

It's definately something to consider. To be honest just to understand the basics and the layout of the code has been a good start. I've only read the 1 full book so far so it's not like I'm deep into C anyway.
I have my interview with the college tutor some time in May so I'll discuss it with him in depth, for now I'm just familiarising myself with this and that.

Oh and writing a programme that works > AA
RedBullGaveMeWings is offline   Reply With Quote
Old 04-10-2012, 01:00 PM   #18
centurion
 
Join Date: Dec 2011
Location: Cloud 9
Posts: 145
Re: Any C experts out there

Quote:
Originally Posted by clowntable View Post
I think it's easier if you'd start with a much simpler program to understand this. Forget the exercise in the book and try this one:
Write a program that reads a decimal and prints it to the screen


Once that's comiling and running you're already halfway there
I just made this one....is this what you mean?

Its output is:
Enter a number to two decimal places: 1.23
You entered 1.23
Code:
#include <stdio.h>

int main()
{
    float aces_up;

    printf("Enter a number to two decimal places: ");
    scanf("%f", &aces_up);

    printf("You entered %.2f", aces_up);

    return 0;
}
I hope this is what you meant lol

Last edited by _dave_; 04-10-2012 at 03:56 PM. Reason: even more code tags
RedBullGaveMeWings is offline   Reply With Quote
Old 04-10-2012, 01:11 PM   #19
Carpal \'Tunnel
 
gaming_mouse's Avatar
 
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 11,948
Re: Any C experts out there

Quote:
Originally Posted by clowntable View Post
Yeah if you want to learn all 3 I think it's best to actually start with C# (I'd obviously recommend Python or Ruby but C# is fine as well). Some people disagree but I think higher level languages are the better gateway languages.
+1 to this. i wish i had learned high-level programming first. beginning with C is an archaic educational model imo.

it's like, if the final goal is to be an awesome racecar driver, you should get in a car and start driving on day one, not learn about how engine's work first.
gaming_mouse is offline   Reply With Quote
Old 04-10-2012, 01:14 PM   #20
centurion
 
Join Date: Dec 2011
Location: Cloud 9
Posts: 145
Re: Any C experts out there

I will try fizzbuzz maybe tomorrow, my head is already fizzbuzzed for today :-)
RedBullGaveMeWings is offline   Reply With Quote
Old 04-10-2012, 01:48 PM   #21
Carpal \'Tunnel
 
EvilSteve's Avatar
 
Join Date: Mar 2006
Location: party fight subchampion
Posts: 12,080
Re: Any C experts out there

Quote:
Originally Posted by RedBullGaveMeWings View Post
I can't wait to be at a point where I can read something like this and know immediately what to do. Although I'm fairly adept at math, getting the compiler to do this is not yet part of my 'C knowledge'.

The reason I was going for the other method was in the book the author gives the hint 'Use if statements to test the number. For example, if the number is between 0 and 9, it has one digit. If the number is between 10 and 99, it has two digits.'

It's early on in the book so the author probably doesn't expect the readers to know all the shortcuts yet.

Thanks for the reply :-)
Ok and I realize the problem asks you to (arbitrarily) treat 5 digit or more numbers as illegal input, so you're doing what the book is asking for, but if you're familiar with while loops (or recursion) and integer division this is really the wrong way to go about it. Always seek a general solution where possible. Here's what that would look like (I am making one assumption though, which is that the number is non-negative).

Code:
int digits = 1;
while (number > 9) {
    ++digits;
    number /= 10;
}
printf("%d digits/n", digits);
I think it would be worthwhile for you to try to understand how that works. In case you're not familiar with the syntax, "++digits" could also be written as "digits = digits + 1", and "number /= 10" is shorthand for "number = number / 10". One thing that might help would be to print the value of number within the loop so you can see how integer division strips off the last digit each time. Also, if you need the value of number to remain unchanged, just copy the value into another variable and do the division on that variable instead within the loop.
EvilSteve is offline   Reply With Quote
Old 04-10-2012, 02:06 PM   #22
centurion
 
Join Date: Dec 2011
Location: Cloud 9
Posts: 145
Re: Any C experts out there

Thanks Steve, all of this info really is invaluable. I touched on the incrementers and decerementors (pardon spelling) in 'C for dummies', and also a little so far in 'A modern approach'. I actually like the ++ and the -- and all the other fancy things. Both authors so far have said they do not like them, but I think people who are generally adept at math can appreciate the little shortcutty things.

I understand how your above code works, for me at the moment it's being able to write something like that without reference, but I'm only 2 weeks into learning so I'm sure you'll allow me that :-)

I'm also interested in the layout of other things such as parentheses. Dan Gookin (C for dummies) likes to have everything, where possible, on different lines i.e

while (number > 9)
{
++digits

whereas K.N King (A modern approach) prefers your method above, with the 1st parenthesis on the same line as 'while', which I think I also do.

I'm currently downloading C# for dummies on the advice of people above. Will the small amount I've learned in C be at all helpful in starting C#? Or is it completely different? Also is the dev-gcc compiler I'm using now going to work with #?

Cheers guys.
RedBullGaveMeWings is offline   Reply With Quote
Old 04-10-2012, 02:41 PM   #23
adept
 
Join Date: Apr 2010
Location: Deep end of the player pool
Posts: 733
Re: Any C experts out there

Quote:
Originally Posted by gaming_mouse View Post
+1 to this. i wish i had learned high-level programming first. beginning with C is an archaic educational model imo.

it's like, if the final goal is to be an awesome racecar driver, you should get in a car and start driving on day one, not learn about how engine's work first.
Generally I agree with this, but I think it also depends on what you are studying. For some engineers (including myself) it makes to start with the low level stuff I think. If your job will most likely be to program micro controllers it makes sense to start Digital technology and assembly and move on to somethin like C, since it is important that one understands the hardware inside out. Also such things as object orientation is out the window in most such cases since it cant be used. But for CS you are right on the money I think
myNameIsInga is offline   Reply With Quote
Old 04-10-2012, 02:48 PM   #24
adept
 
Join Date: Apr 2010
Location: Deep end of the player pool
Posts: 733
Re: Any C experts out there

Quote:
Originally Posted by RedBullGaveMeWings View Post
Thanks Steve, all of this info really is invaluable. I touched on the incrementers and decerementors (pardon spelling) in 'C for dummies', and also a little so far in 'A modern approach'. I actually like the ++ and the -- and all the other fancy things. Both authors so far have said they do not like them, but I think people who are generally adept at math can appreciate the little shortcutty things.

I understand how your above code works, for me at the moment it's being able to write something like that without reference, but I'm only 2 weeks into learning so I'm sure you'll allow me that :-)

I'm also interested in the layout of other things such as parentheses. Dan Gookin (C for dummies) likes to have everything, where possible, on different lines i.e

while (number > 9)
{
++digits

whereas K.N King (A modern approach) prefers your method above, with the 1st parenthesis on the same line as 'while', which I think I also do.

I'm currently downloading C# for dummies on the advice of people above. Will the small amount I've learned in C be at all helpful in starting C#? Or is it completely different? Also is the dev-gcc compiler I'm using now going to work with #?

Cheers guys.
There are many different styles and everyone has their own favorite way of coding. If there is a clearly stated standard style for a language, use that. If a teacher has a preference you may use that. Certainly when you are employed you obey the coding standards layed out by the company. For your own stuff, its not so important which you choose, just be consistent.

Also there is a thread on that here o the first page
myNameIsInga is offline   Reply With Quote
Old 04-10-2012, 02:49 PM   #25
Carpal \'Tunnel
 
gaming_mouse's Avatar
 
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 11,948
Re: Any C experts out there

Quote:
Originally Posted by myNameIsInga View Post
Generally I agree with this, but I think it also depends on what you are studying. For some engineers (including myself) it makes to start with the low level stuff I think. If your job will most likely be to program micro controllers it makes sense to start Digital technology and assembly and move on to somethin like C, since it is important that one understands the hardware inside out. Also such things as object orientation is out the window in most such cases since it cant be used. But for CS you are right on the money I think
i was going to add your caveat to my original post, but it's clear that OP's current goal is not to become a low level systems engineer, so i thought it would just muddle the more important point.
gaming_mouse is offline   Reply With Quote
Old 04-10-2012, 02:50 PM   #26
adept
 
Join Date: Apr 2010
Location: Deep end of the player pool
Posts: 733
Re: Any C experts out there

Quote:
Originally Posted by gaming_mouse View Post
i was going to add your caveat to my original post, but it's clear that OP's current goal is not to become a low level systems engineer, so i thought it would just muddle the more important point.
your right
myNameIsInga is offline   Reply With Quote
Old 04-10-2012, 02:50 PM   #27
Carpal \'Tunnel
 
EvilSteve's Avatar
 
Join Date: Mar 2006
Location: party fight subchampion
Posts: 12,080
Re: Any C experts out there

I can't speak for C# but the only thing that would be different in any of the above code in C++ would be the input/output stuff. And even that you could do the C way in C++, but you probably wouldn't want to. Given a choice of those three languages if you're starting from scratch, I agree with the advice given to start with C#. I don't think it hurts you to learn C though, and if you already know some C, might as well continue with it. The computer science concepts you learn will be universally applicable in any case even if the particulars differ.

There are different ways to format your code and lots of lengthy arguments about that. It gives people who like to argue something to keep them occupied indefinitely. Just pick a reasonable way to format your code and be consistent about it. However the code is formatted in whatever book you're reading should be fine. Later, after you've been exposed to code written in different ways, you can decide what system you like. I wouldn't worry about it too much now.
EvilSteve is offline   Reply With Quote
Old 04-10-2012, 03:10 PM   #28
Carpal \'Tunnel
 
EvilSteve's Avatar
 
Join Date: Mar 2006
Location: party fight subchampion
Posts: 12,080
Re: Any C experts out there

Quote:
Originally Posted by RedBullGaveMeWings View Post
Thanks Steve, all of this info really is invaluable. I touched on the incrementers and decerementors (pardon spelling) in 'C for dummies', and also a little so far in 'A modern approach'. I actually like the ++ and the -- and all the other fancy things. Both authors so far have said they do not like them, but I think people who are generally adept at math can appreciate the little shortcutty things.
Anyone telling you to avoid ++ and -- operators in C is just being silly. Now, if what they're saying is that they don't recommend using ++ and -- on the right side of expressions (such that you have to pay close attention to whether you're using pre-increment or post-increment because it will affect the value of the assignment), then they have a point. That's going to generate some confusing code especially for beginners. But everyone uses those operators, just try to avoid them within complex expressions. Putting something like ++i (or i++ but I'd recommend being consistent and using only one or the other) on a line by itself is 100% fine. In fact it would look weird to write "i = i + 1"
EvilSteve is offline   Reply With Quote
Old 04-10-2012, 04:10 PM   #29
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK
Posts: 9,148
Re: Any C experts out there

Quote:
Originally Posted by RedBullGaveMeWings View Post
Well, I'm going in September to study a HNC in Computing & System Development, leading on to a degree probably in Computer Science. Although I have a good knowledge of computers already, I've never delved into any programming type thingies. The preface to most of the books looked at state that the best place to start is C, so I went through C for dummies, now this one. If you have any better suggestions on books I should read I would very appreciative :-)
Def read "The C Programming Language, K&R", code the examples.

gaming_mouse and Inga make fair points, but I recommend sticking with C. I actually learned JavaScript first, it's like "easy mode" C. But I've done a HNC and Comp Sci degree not too long ago (prob 6 years or so), from that you must be in the UK? Knowing plain C will be incredibly useful, languages taught in my lessons were C, prolog, more C, basic C++, VBA for ms access DB, PL/SQL for Oracle DB. My friend at a different uni did most stuff in Java.

I'd say forget C++ / C# for now, spend a month+ going through basic C books / examples, being able to read C will greatly help the learning of others later. jumping between languages at the start might be very confusing!

But of course speak to your tutor and find out what languages wil likely be taught, things probably vary quite a lot over the years and between institutions.

and please use [code] [/code] tags when you post code here, it makes it much easier to read
_dave_ is offline   Reply With Quote
Old 04-10-2012, 04:15 PM   #30
Carpal \'Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 11,090
Re: Any C experts out there

Quote:
Originally Posted by gaming_mouse View Post
i wish i had learned high-level programming first. beginning with C is an archaic educational model imo.
Definitely my opinion too.
jjshabado is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -4. The time now is 04:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.
Copyright © 2008-2010, Two Plus Two Interactive