Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The getchar compiles an error?

Status
Not open for further replies.

Namsu55

Technical User
Aug 14, 2006
8
GB
Hi, I am learning C, I am using this book called "The C Programming Language, 2nd Edition" by Brian M. Ritchie. I have gotten to the point of learning charachter Input and Output, the book uses this following code which I have written and tried but compiles an error:

#include <stdio.h>

/*copy input to output - 1st version*/

main()

int c;

c = getchar();

while (c != EOF) {
putchar(c);
c = getchar();

}

}

Why does it give me an error. I am using Bloodshed C++ 4.9.9.2 and tried this program on Turbo C. The code comes directly from the book, all other programs were functional up to this point. Can any body help me, thankyou.
 
Please use [code][/code] tags when posting code.

> Why does it give me an error.
Well there's a missing { somewhere shortly after main()

> Brian M. Ritchie.
That's Brian Kernighan and Dennis Ritchie.

--
 
main() should also return an int, although that's not the cause of the error.
Code:
int main()
{
   ...
   return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top