Thread: Approaching C

  1. #1
    Insomniac
    Join Date
    Mar 2004
    Posts
    35

    Approaching C

    Hey..
    I started learning C with K&R's 2nd ed. and I found the logic to be somewhat confusing. With this in mind, I picked up one of those (dreaded) learn x in 21 days books.. Needless to say the examples are bad, the typo's are worse, and the code answers for problems are flawed.

    I've come to the conclusion that maybe it's how I'm approaching C. I do examples and I answer the questions, but the logic still bugs me.

    Generally I'm asking for advice on how to approach the language.

    Any pointers welcomed. thanks :/

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    any pointer, stay away from pointer for now. (sorry, couldn't avoid the pun.) What I do is read most of the book, then look at the previous examples, usually I understand them better when they explain more of the topic. That is my tip.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Stick with K&R2 - if it gets to be too much, leave it for a bit, but refer back to it often. Sometimes if you let something percolate for a while it soaks in and you *get it* later. A nice set of notes to go along with that book is found here. Quite often I have found that something in the book would stump me and the answer would be in Summit's notes.

    ~/

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Generally I'm asking for advice on how to approach the language.
    Carefully. If C is your first language then you will likely have trouble with it, but keep digging and everything will become clear. C isn't a good first language, but it is very rewarding. I highly recommend referring to K&R regularly as well as frequenting these forums. If you have questions, great. We can answer them. If you don't have questions, great. You can lurk and learn from other people's questions. Eventually though you'll want to try your hand at answering questions. You'll find that your own understanding improves drastically when somebody corrects you, and if you aren't corrected often then you're an asset.
    My best code is written with the delete key.

  5. #5
    Insomniac
    Join Date
    Mar 2004
    Posts
    35
    ty for the replies (and the pun :P).
    The note resource looks very useful. ty for the link.
    If you have questions, great. We can answer them
    Thanks for that as well, after reading the FAQ and the two stickies, I wasn't too sure whether there were trolls around. Now I know it's looking hopeful.

    A quick query concerning the irc channel, is it active?

    thanks again for the responses, V. helpful.
    Last edited by olbas; 03-08-2004 at 04:21 PM.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I wasn't too sure whether there were trolls around.
    We have our share of trolls, but they usually don't stay long once we've made them nice and toasty.

    >A quick query concerning the irc channel, is it active?
    Not much anymore.
    My best code is written with the delete key.

  7. #7
    Insomniac
    Join Date
    Mar 2004
    Posts
    35
    Disappointing news about the channel, I'll wonder in there later have a look.

    Them there trolls starting to sound pretty tasty, think i'll go eat

    Thanks for the help anyways

  8. #8
    Insomniac
    Join Date
    Mar 2004
    Posts
    35
    I'm currently at the end of chapter one (k&r 2ed.), with exercise 1-23 making me a little worried.
    I've gone through the book three times now, and each time I see this exercise, I get the impression I've missed something.

    I'm already aware that I should use fopen or something similiar for this, but I see no reference to it, or any information regarding where to look. (I already know where, but still..)

    It's a pretty big step with no information.

    Any guidance appreciated.

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    Insomniac
    Join Date
    Mar 2004
    Posts
    35
    So I haven't missed anything...
    Though now I'm wondering just _how_ that program is meant to function.

    The task is to write a program to remove all comments from a c file. It's both impratical and just lacks any point to copying the contents of a file to console or whatever you use.

    Great so the program works in a minimalistic fashion...

    Am I lacking something, or does this seem completly pointless

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    /* test.c */
    #include <stdio.h>
    
    int main(void)
    {
       /*
        * I built Ben Pfaff's version, but I had to change this section:
        *    if (c == EOF) {
        *        if (state == SLASH)
        *            putchar('/');
        *        break;
        *    }
        */
        puts("Hello world" /* comments */);
        return 0;
    }
    Using pipes, the above code is fed to the comment stripper and this is the output.
    Code:
    H:\test>cstrip < test.c
    
    #include <stdio.h>
    
    int main(void)
    {
             
        puts("Hello world" );
        return 0;
    }
    If I wanted to pipe the output to a file, I could do that just as well.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #12
    Insomniac
    Join Date
    Mar 2004
    Posts
    35
    So I just wasn't thinking. I was under the impression that it required command-line arguments.

    Thanks for ummm helping me look a fool, greatly appreciated(not joking)

Popular pages Recent additions subscribe to a feed