© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

C Program To Find Digits, Characters , Spaces , Words , Lines and Specialcharacters

#include main() { FILE *fp; char c; int i,s=0,l=0,sp=0,ch=0,d=0; clrscr(); fp=fopen("file1","w"); while((c=getchar())!=EOF) putc(c,fp); fclose(fp); fp=fopen("file1","r"); while((c=getc(fp))!=EOF) { i=c; if(c>='0'&&c<='9') d++; else if(i>=65&&i<=90)ch++; else if(i>=97&&i<=122)ch++; else if(c=='\n')l++; else if(c==' ')s++; else sp++; } fclose(fp); printf("\nDIGITS:%d",d); printf("\nCHARACTERS:%d",ch); printf("\nSPACES:%d",s); printf("\nWORDS:%d",++s); printf("\nLINES:%d",++l); printf("\nSPECIAL CHARACTERS:%d",sp); getch(); }

Sample Output Screen:

Hai welcome to file.
^Z

DIGITS:0
CHARACTERS:16
SPACES:3
WORDS:4
LINES:2
SPECIAL CHARACTERS:1

 
SLogix Student Projects
bottom