Code:
#include<stdio.h>
/* program to calculate no of tabs,spaces,tabs alongwith characters */
int main(){
int c;
int nc,nspc,ntb,nline;
nc=nspc=ntb=nline=0;
c='\0';
while((c=getchar())!=EOF){
++nc;
if(c == ' ')
++nspc;
else if(c=='\t')
++ntb;
else if(c=='\n')
++nline;
else;
}
printf("\ncharacters:%d\tspace:%d\ttabs:%d\tNewlines:%d\t",nc,nspc,ntb,nline);
return 0;
}
i can't find the bug here..i've used a MinGW gcc compiler on a windows machine..
the program compiles correctly...i give it ctrl+c as a end of file indicator..
the programs runs fine the first time..but start giving problems..after wards..sometimes the second last (printf) statement is not executed @ ctrl+c combination...
other times the printf statement contains all 0 zero values ..pls help