learning c

ed baron baron at bnlux0.bnl.gov
Sun Apr 2 01:40:44 AEST 1989


Maybe this isn't the best place to post this but it seemed reasonable.

I am trying to learn c out of a book that seems to be wrong on many
things, but anyway i can't seem to figure out how getchar() should
work. consider the following

char name [10];
int c;

for(;;)
{
puts("enter 9 to exit");
c = getchar();
if(c == 9)
break;
puts("enter name: ");
gets(name);
.
.
.
}

now getchar gets one character but not until it sees the terminator
(carriage return) but since it only gets one character and the
carriage return is one character if you enter 1<cr> say
the <cr> is passed to the next thing seeking input and so now
name is just <cr> i.e there is no opportunity to respond to the naame
prompt. then i tried using gets(c) in place of getchar c (andd
declaring c to be char) but that won't compile. what is the proper
way to do this? please respond via mail. thanks.

ed baron (baron at bnlux0.bnl.gov, baron at bnlux0.bitnet)



More information about the Comp.lang.c mailing list