#include <stdio.h>
#include <conio.h>
int main()
{
char str[80];
int cnt[122];
int i;
for (i=0;i<122;++i)
cnt[i]=0;
clrscr();
printf("Enter a string less than 80 characters: ");
gets( str );
int wrong = 0;
for(i=0; str[i] != '\0'; ++i)
{
if (((str[i]>='a') && (str[i]<='z'))||((str[i]>='A') && (str[i]<='Z')))
{
++cnt[str[i]];
}
else
{
printf("Wrong Input.\n");
return 1;
}
}
for (i=0;i<122;++i)
{
if (cnt[i]>0)
{
printf ("%c = %d\n",(char)i,cnt[i]);
}
}
getch();
return 0;
}
1. when i run the program it says "Expression syntax error on function main." in the expression int wrong = 0;
2. and when i enter a numerical character. it doesn't say Wrong input, although we put Wrong input in else, but instead it closes the program and turns back to the blue IDE. It should say wrong input and will require a user to enter another word.
3. and when i enter a compound word like mother-in-law , it will display the character '-' and will show how many times it appear.
Though it should not be, only the alphabet would be display e.g. (mother-in-law = a,e,h,i,l,m,n,r,t,w) the dash must not be displayed.
Edited by WingedPanther, 28 January 2012 - 06:24 PM.
add code tags (the # button)


Sign In
Create Account


Back to top









