GCC don't compile codes from the book "The C Programming Language".

This is a discussion on GCC don't compile codes from the book "The C Programming Language". within the C Programming forums, part of the General Programming Boards category; Hello, I was reading this amazing book by Dennis Ritchie (RIP) and some codes just don't compile. I can understand ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    6

    Question GCC don't compile codes from the book "The C Programming Language".

    Hello,

    I was reading this amazing book by Dennis Ritchie (RIP) and some codes just don't compile. I can understand the logic of the program, but somehow, GCC don't accept it. For instance, for this code, GCC returns "cprog.c:17:3: error: lvalue required as left operand of assignment".
    Code:
    1. #include<stdio.h>
    2. #define IN 1 /* inside a word */
    3. #define OUT 0 /* outside a word */
    4. /* count lines, words, and characters in input */
    5. int main(){
    6. int c, nl, nw, nc, state;
    7. state = OUT;
    8. nl = nw = nc = 0;
    9. while((c = getchar()) != EOF){
    10. nc++;
    11. if(c =='\n')
    12. nl++;
    13. if(c == ' ' || c == '\n' || c = '\t')
    14. state = OUT;
    15. else if(state == OUT){
    16. state = IN;
    17. nw++;
    18. }
    19. }
    20. printf("%d %d %d\n", nl, nw, nc);
    21. }
    p.s: Here in the forum, the code tags don't accept blank lines. In my code, the line number 17 is:

    if(c == ' ' || c == '\n' || c = '\t')
    Can someone plz give me a hand here?

    Many tnx in advance!
    Last edited by XVirtusX; 11-19-2011 at 07:48 PM.

  2. #2
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Code:
    c = '\t'
    At line 13.
    Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
    What profit hath a man of all his labour which he taketh under the sun?
    All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
    For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,667
    Typo on line 13. The third test needs two equal signs, not one.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    6
    Jeez, I felt like a stupid now... tnx for the fast reply guys!

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,667
    Quote Originally Posted by XVirtusX View Post
    Jeez, I felt like a stupid now...
    Ah, not the objective, but a fringe benefit sometimes
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question on the book "C Programming Language" by K&R
    By noahian in forum C Programming
    Replies: 3
    Last Post: 09-04-2011, 03:56 PM
  2. Doubt in "C Programming Language by K & R"
    By ackr1201 in forum C Programming
    Replies: 5
    Last Post: 07-12-2011, 11:34 AM
  3. Need "if","for loop",&"else" source codes
    By dn_angel_07 in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2009, 11:01 PM
  4. Replies: 1
    Last Post: 11-16-2007, 08:31 PM
  5. Question about the book "The C Programming Language"
    By caduardo21 in forum C Programming
    Replies: 4
    Last Post: 05-15-2005, 02:22 PM

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