0

Thank you for reading my thread,I am new to C and I have a big problem -Naturally.I cant seem to compile thise code:

# define EOF =-1
main()
{ 
   int c,nl; // integers 
   nl = 0;  // assignment int ln to 0 value

        while ((c = getchar() !=EOF) // problem area :-(
                if (c =='\n') // here I believe the '\n' char means new line
                    ++nl;
        printf("%d\n",nl);
}

The purpose of the code is to count the number of keys pressed :rolleyes:
but regardless of that, my problem start when I compile the code - it outputs error with 'while' line7 after = but other times :sad: error after ; which I obviously do not have:confused:

I am running on linux and my compiler is some strange application I read about in some dump e-book I downloaded some where(can't remember URL :sad: ) a few years ago called cc.

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by Salem
0

the problem is

#define EOF =-1
while ((c = getchar() !=EOF) // problem area :-(

replace it with

#define EOF -1
while ((c = getchar()) != EOF) // problem area :-(
0

Thank you very much andor ;) I remember it now, 'cause I read about it in my dump e-book - just a few pages into the chapter.Thank you again for helping me out :o

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.