Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Programming begginer

  1. #11
    Join Date
    Apr 2004
    Posts
    554
    Rep Power
    0

    Default Re:Programming begginer

    I'm trying to learn C, have a copy of "The C programming Language" and the Miracle C compiler. Started last night at about 10 pm and ran into a problem. When I wrote the character counting program it wouldn't count the characters.....well, it wouldn't print the result anyway. I recoded and even cut and paste from the book. Could it be the compiler?

  2. #12
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default Re:Programming begginer

    It could be the compiler, but I doubt it, when I was learning C, many times the same thing happened to me, when I copied word for word from the book and the code didnt work, and no matter how hard I looked i couldnt find what was wrong. But usually after looking at it for a very long time, you realise you did type something wrong. Its about getting used to the code. Also not all text books are bug free. It could really be that their is something wrong with the code in the book. You should post your code on the forum if its small enought, so that trained eyes can take a look for bugs

  3. #13
    Join Date
    Apr 2004
    Posts
    554
    Rep Power
    0

    Default Re:Programming begginer

    Here's the code........

    #include <stdio.h>

    main()
    {
    double nc;

    for (nc = 0; gechar() != EOF; ++nc)
    ;
    printf("%.0f\n", nc);
    }

    This is really baffling me, I grasped the concepts b4 this pretty quickly, and i don't want to skip this.

  4. #14
    Join Date
    Jun 2004
    Posts
    27
    Rep Power
    0

    Default Re:Programming begginer

    hey anybody know where I can get a good C/C++ tut and compiler for free
    ???

  5. #15
    Join Date
    May 2003
    Posts
    229
    Rep Power
    0

    Default Re:Programming begginer

    Nigelt,

    I looked at the code you posted, and it appears to have a syntax error. The call to gechar looks like it should be getchar, but I don't know what non-standard functions your compiler may have implemented, so I can't say for sure.

    If this isn't helpful, then you should post some more information. You say "When I wrote the character counting program it wouldn't count the characters.....well, it wouldn't print the result anyway", but you didn't say what the code did do". It is difficult to guess what the problem is without more information.

    Stuart

  6. #16
    Join Date
    Apr 2004
    Posts
    554
    Rep Power
    0

    Default Re:Programming begginer

    @sking
    I saw the syntax error and corrected it prior to posting. The code I posted was cut and paste from the book. When the program is run and you type charcaters and press enter, there is a small pause and then a new line. No character count at all. There are 2 versions in the book and I've tried them both. Any suggestions?

  7. #17
    Join Date
    Jun 2004
    Posts
    3
    Rep Power
    0

    Default Re:Programming begginer

    I have mess around with several languages and Dietel books are the worse of its kind. I don't think they are programmers they are just doing business. I used their java, c and c++ and it the same stupid examples they use in all of them. Try www.bruceeckel.com

  8. #18
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default Re:Programming begginer

    I know the problem, I just compiled and ran the program, apart from the syntax error which I fixed. there was something that you dont realize. In order for the character count to start you have to enter the EOF character. NOT THE ENTER CHARACTER!! That will give you a new line but it isnt the same as EOF. to get EOF, type Ctrl+Z (that is holding down the Ctrl key and the Z at the same time).
    If you are using Linux or Unix, the EOF is Ctrl+D. You might have to type it twice or more. I did that! and I got it to work. AS you can see from code that it reads characters until it encounters an EOF.


    By the way, Deitel and Deitel books really are good books. I've always used them and learnt tons from them.

  9. #19
    Join Date
    Apr 2004
    Posts
    554
    Rep Power
    0

    Default Re:Programming begginer

    Ohhhhhhh!!! Thanks a lot alexdevmaster......I've been stuck on that program for a while. I can finally move on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •