Whats wrong with this?
I am a newbie plz help!
what is wrong???
#include <stdio.h>
main()
{
int c, nl, np, nq;
printf("Press ENTER and then CTRL+C to finish input\n");
nl = 0;
np = 0;
nq = 0;
while ((c = getchar()) != EOF)
if(c == '\n')
++nl;
if(c == '\t')
++np;
if(c == ' ')
++nq;
printf("FINAL REPORT:\n");
printf("Blanks: %d\n", nq);
printf("Lines: %d\n", nl);
printf("Tabs: %d\n", np);
}
It only sez the correct number of lines and everything else is incorrwctly zero.
If i do this:
#include <stdio.h>
main()
{
int c, nl, np, nq;
printf("Press ENTER and then CTRL+C to finish input\n");
nl = 0;
np = 0;
nq = 0;
while ((c = getchar()) != EOF)
if(c == '\t')
++np;
if(c == '\n')
++nl;
if(c == ' ')
++nq;
printf("FINAL REPORT:\n");
printf("Blanks: %d\n", nq);
printf("Lines: %d\n", nl);
printf("Tabs: %d\n", np);
}
Thx 4 Help.