right approach!

This is a discussion on right approach! within the C Programming forums, part of the General Programming Boards category; I have just got admission into Computer Engineering and the first subject we are taught is C prog language.I dont ...

  1. #1
    tarun
    Guest

    right approach!

    I have just got admission into Computer Engineering and the first subject we are taught is C prog language.I dont want to faulter in the beginning.I would appreciate if somebody told me the kind of approach I should take and the books I should read to enhance my programming skills!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Rule #1: If they use "void main", get a new book or a new teacher.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I would appreciate if somebody told me the kind of approach I should take and the books I should read
    A few simple questions for instructors:
    1) What is wrong with 'void main', if anything?
    2) How can I flush the input stream?
    3) *advanced* How do I portably tell if a computer is big-endian or little-endian at run-time?
    4) Is gets() a good way to read string input?
    5) What do you think of goto?
    6) Is '*a ^= *b ^= *a ^= *b' a good way to swap two variables?

    Here are the answers you should expect from someone knowledgeable:
    1) Two things: There could be a naming conflict and the program will not run at all, or the return value will be garbage and cause undefined behavior.
    2) There's no portable way to do this, but the best method is to use a loop which reads until either a newline character or EOF.
    3) There is no portable way since not all machines use either big-endian or little-endian.
    4) No, gets() is wrong because it doesn't check for boundaries of the buffer you pass to it. Every time you use gets() you risk writing into memory that you do not own, which is very bad.
    5) goto should be avoided when possible because there are more structured ways to write code. There are times when goto is the best choice, but those times are few and far between.
    6) No, this method is completely undefined because you modify a variable more than once between sequence points. A correct modification would be:
    Code:
    *a ^= *b;
    *b ^= *a;
    *a ^= *b;
    But this is still dangerous for anything but integer values, even then the integer values may break if the pointers point to the same locations in memory.

    Now a few things to look for in books:
    1) void main
    2) fflush ( stdin )
    3) Heavy use of gets() or scanf() with no mention of fgets().
    4) Code that doesn't check return values often.
    5) Code that assigns to pointers that haven't been allocated memory, like so:
    Code:
    char *p;
    .
    .
    gets ( p );
    6) Any book by Herbert Schildt
    7) Any book by Greg Perry

    Some of these can be ignored if you know what you are doing, but for a beginner, any of the above means that you 'probably' cannot trust anything in the book and you should double check everything you read in it.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Unregistered
    Guest
    Prelude, I haven't read anything by Schildt, but in Perry's case, do you think it's possible that his ability to explain things from the point of view of new programmers makes up for his errors?

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >do you think it's possible that his ability to explain things from
    >the point of view of new programmers makes up for his errors?
    If you teach incorrect things in a simple way, does that make them correct?

    -Prelude
    My best code is written with the delete key.

  6. #6
    Nick
    Guest
    When you first learn programing you want to
    learn how to program any language not just c.

    I've seen some otherwise very knowledgeable people
    use code that it void main so if your teacher uses it's not
    grounds for dismisal. But if you write a book only about
    c that contains void main then that's pretty bad.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>void main so if your teacher uses it's not grounds for dismisal
    Maybe not dismisal, but still a severe slapping. If someone is teaching you, they should teach you correctly. And the matter of void main vs int main in your wording simpy comes down to the teacher being too lazy to code a return value at the end of main. This is not a good excuse, imo.

    If you are learning programming in general, not specifically C, then maybe your teacher should use pseudo code instead. That way, they can use whatever statements they want.

    (just my 2 cents )
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Unregistered
    Guest
    Prelude, you can't seem to get past the errors. Errors can be corrected. Everyone in the world makes errors, unless they do absolutely nothing. The vast majority of what Perry teaches is good.

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Prelude, you can't seem to get past the errors.
    I don't mean just typegraphical errors, I mean valid technical errors where the author is dead wrong in the explanation. I'm well aware that a book can contain mistakes after printing.

    >The vast majority of what Perry teaches is good.
    That is your opinion. Mine is different. You can't seem to get past that.

    -Prelude
    My best code is written with the delete key.

  10. #10
    Unregistered
    Guest
    Prelude, the errors are a small part of the books. Shouldn't you also look at the good points.
    Incidently, males and female write differently (unless they're really twisted).

  11. #11
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    Get yourself a Pocket C Reference Guide. It will be your constant companion and reading it will help learn faster.
    It is not the spoon that bends, it is you who bends around the spoon.

  12. #12
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    I don't know who Greg Perry is, but I bet that Tom Swan wants to kick his ass.

  13. #13
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Shouldn't you also look at the good points.
    I will concede that for some budding programmers, simplicity is more important than accuracy. I don't agree with this method of teaching, though if it works and the errors are corrected before bad habits are formed I see little wrong. The problem is that the errors usually are not corrected before the student gets into the habit of writing broken code.

    >Incidently, males and female write differently (unless they're really twisted).
    What bearing does this have on Greg Perry?

    -Prelude
    My best code is written with the delete key.

  14. #14
    aurė entuluva! mithrandir's Avatar
    Join Date
    Aug 2001
    Posts
    1,209
    The best way to learn programming is to learn the concepts, try your hand at example code of those concepts.

    The most important thing you can do is focus on concepts first

    If you don't understand why you're doing something, you're sure as heck not going to understand how to do something.

    Just one thing - if you are having trouble in your class, scream up and down and shout for H-E-L-P! Don't sit there like a potato - be very vocal if you need help from your lecturer/tutor. After all, you are paying for it and you are paying for their help!

  15. #15
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    If you want to learn C properly the book to read is:

    The ANSI C Programming Language (second edition) by Brian W. Kerninghan and Dennis M. Ritchie
    ISBN 0-13-110362-8

    thankyou goodbye.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unsure on how to approach this concurrency problem
    By osiris^ in forum C# Programming
    Replies: 3
    Last Post: 04-29-2008, 11:47 PM
  2. Best Approach for Learning
    By UCnLA in forum C Programming
    Replies: 5
    Last Post: 03-21-2008, 02:35 AM
  3. Best approach
    By DV64h in forum Networking/Device Communication
    Replies: 6
    Last Post: 12-10-2006, 02:24 PM
  4. Object oriented approach in C
    By arunj in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2006, 12:39 AM
  5. software development approach...
    By dkt in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-16-2001, 09:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21