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.

Recommended Answers

All 3 Replies

the problem is

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

replace it with

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

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

> # define EOF =-1
You should really have #include <stdio.h>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.