|
From: <or...@vp...> - 2002-11-19 21:42:07
|
Hello Paul!
Tuesday, November 19, 2002, 9:55:35 PM, you wrote:
PA> Hi again!
PA> Is there an equivalent of clrscr() in Dev-C++?
I don't know.
PA> Also can you give me a solution for the counting characters program?
PA> I tried the following but it seems that the printf statement is not
PA> executed.
Yes.
I suggest you should write it like this:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int nc; /* use integer instead of double for counting */
for(nc=0;getchar()!=EOF;nc++)
;
printf("\n");
printf("%d\n",nc); /* print as integer */
system("PAUSE");
return 0;
}
Well, the printf() function executes, but it seems that it doesn't
print out anything until you print a newline ('\n') first. I don't
exactly know why this is needed.
If you try the original code (without the first '\n') with a file,
you'll notice that it works. It seems that printf() thinks it is still
at EOF of stdout, until you print '\n'. (which is a foolishness,
because you read from stdin, and stdin reaches EOF!!!) But this only
happens, when you type from the console. When you use a file, it works
normally. (for example: count.exe < file.txt)
--
Best regards,
Oroszi Balázs mailto:or...@vp...
PGP-FP: FB80 8A43 2664 6126 E465 46E2 2546 CFA3 C25B 9F70
finger -l or...@se...
|