question

D

Darklight

i wrote this program to day for the answer to
ex 1-7 write a program to print the value of EOF
ANS =

#include<stdio.h>

int main(void)
{
int c;
printf("EOF is %d\n",EOF);

while ((c = getchar()) != EOF)
printf("%c %d\n",c,EOF);
putchar(c);


}


the answer i get is -1 is this the correct answer to the question the
question came from c programming kernighan and ritchie
 
R

Robert Gamble

Darklight said:
i wrote this program to day for the answer to
ex 1-7 write a program to print the value of EOF
ANS =

#include<stdio.h>

int main(void)
{
int c;
printf("EOF is %d\n",EOF);

This statement alone satisfies your stated requirement.
while ((c = getchar()) != EOF)
printf("%c %d\n",c,EOF);
putchar(c);

Not sure what you are trying to do here but it doesn't look
particularly useful and you shouldn't be trying to putchar EOF which is
what c will be when the loop exits.

missing return value here.
}


the answer i get is -1 is this the correct answer to the question the
question came from c programming kernighan and ritchie

The first part of your program is the correct way to determine this
value on your implementation, on many systems the value is -1.

Robert Gamble
 
D

Darklight

Robert said:
This statement alone satisfies your stated requirement.

Thanks for your help the reason for the printf("%c %d\n",c,EOF);
statement is to see if the value changed thats me being curious
and a novice thanks again!!

Owe i do have the c answer book but i had to make sure what i was reading
was correct as it said something different in the book
 
P

pete

Robert said:
Darklight wrote:

This statement alone satisfies your stated requirement.
The first part of your program is the correct way to determine this
value on your implementation, on many systems the value is -1.

And EOF is negative on all systems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top