Why doesn't this work? (3B2 problem)
Ken B
ken at birtch.UUCP
Fri Mar 21 07:40:16 AEST 1986
We have a 3B2/300, and I wrote this program to help debug our spooler problem
(another story), why doesn't it work? It never read's an EOF from stdin,
and continues to dump 'nulls' to stdout. (Note: I'm just learning 'c',
so please no flames on programming style, or lack of it)
All the program does is number each line it reads from stdin.
--------- code follows ---------
#include <stdio.h>
main()
{
int i=1;
char c;
c=getchar();
if (c!=EOF)
printf("%d ",i++);
while (c!=EOF) {
putchar(c);
if (c=='\n') {
c=getchar();
if (c!=EOF)
printf("%d ",i++);
}
else c=getchar();
}
putchar(EOF);
}
------ end of code ------
The system is running Sys V un*x, if that helps. The program works, except
that it never stops running. I am forced to interrupt it, which writes the
data out, with alot of nulls on the 'last line'. Am I doing something wrong?
This exact program works correctly on our Pyramid 90x, so I know its not just
my program.
If anyone out there has some ideas on why it doesn't ever read an EOF, I'd
be very grateful to know why.
Note: how I use it is:
ls -la /bin | number > outputfile
or
ls -la /bin | number
Niether method works correctly (i.e. stops executing)
Thank you,
Ken Brown
--
uucp: ...{!glacier!oliveb,!ihnp4!trwrb} !felix!birtch!ken
These ramblings are my own, and are surely not those of my employer.
More information about the Comp.lang.c
mailing list