Code: #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50]; int i,len=0,word=1,sant=0,space=0,vow=0,cons=0,line=1; clrscr(); printf("plz enter the string\n"); gets(a); /*len=strlen(a);*/ /* OR */ for(i=0;a[i]!='\0';i++) { len++; } for(i=0;i<=len;i++) { if(a[i]==' ') { space++; } if(a[i]==' '&&(a[i]>='a'||a[i]<='z')) { word++; } else if(a[i]=='.') { sant++; } else if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u'||a[i]=='A'||a[i]=='E'||a[i]=='I'||a[i]=='O'||a[i]=='U') { vow++; } else if(a[i]=='b'||a[i]=='c'||a[i]=='d'||a[i]=='f'||a[i]=='g'||a[i]=='h'||a[i]=='j'||a[i]=='k'||a[i]=='l'||a[i]=='m'||a[i]=='n'||a[i]=='p'||a[i]=='q'||a[i]=='r'||a[i]=='s'||a[i]=='t'||a[i]=='v'||a[i]=='w'||a[i]=='x'||a[i]=='y'||a[i]=='z'||a[i]=='B'||a[i]=='C'||a[i]=='D'||a[i]=='F'||a[i]=='G'||a[i]=='H'||a[i]=='J'||a[i]=='K'||a[i]=='L'||a[i]=='M'||a[i]=='N'||a[i]=='P'||a[i]=='Q'||a[i]=='R'||a[i]=='S'||a[i]=='T'||a[i]=='V'||a[i]=='W'||a[i]=='X'||a[i]=='Y'||a[i]=='Z') { cons++; } else if(a[i]=='\n') { line++; } } printf(" length=%d\n words=%d\n space=%d\n santence=%d\n vowel=%d\n consonent=%d\n",len,word,space,sant,vow,cons); printf(" line=%d",line); getch(); }
Interesting, could you explain what you think this will do? Code: if(a[i]==' '&&(a[i]>='a'||a[i]<='z'))
Please dont use 'gets()' in your code. It is a handy tool for hackers to intrude into your programs. Spare some time and read : http://cboard.cprogramming.com/c-programming/25338-why-gets-function-dangerous.html Also, as xpi0t0s said, the condition : Code: if(a[i]==' '&&(a[i]>='a'||a[i]<='z')) does not make any sense. '&&' means that both conditions should be true to enter the 'if' block. But how is this possible for a to be equal to space ' ' and some alphabet (a-z) at the same time?