Xiang
03-10-2003, 10:07 AM
Dear sir,
In my program, users have to enter a word and ends with a period (full-stop). If the users keys in non-alphabetical values, the message 'Error!' will be displayed and strlen(string) should not including (.). I can't displayed the output even my condition is true. Why???
void main(void)
{
char string[100];
int a;
printf("Please enter a word and ends with a full-stop(.)");
gets(string);
while(string[a] != '\0' && string[0] != '.')
{
a++;
}
if (string[--a] != '.')
{
printf("Error!");
}
else
{
if (isalpha(string[a]))
{
printf("The number of letters in a word.");
printf("%s", string);
printf("%i letter(s) in the word", strlen(string));
}
}
Thanks
Xiang
In my program, users have to enter a word and ends with a period (full-stop). If the users keys in non-alphabetical values, the message 'Error!' will be displayed and strlen(string) should not including (.). I can't displayed the output even my condition is true. Why???
void main(void)
{
char string[100];
int a;
printf("Please enter a word and ends with a full-stop(.)");
gets(string);
while(string[a] != '\0' && string[0] != '.')
{
a++;
}
if (string[--a] != '.')
{
printf("Error!");
}
else
{
if (isalpha(string[a]))
{
printf("The number of letters in a word.");
printf("%s", string);
printf("%i letter(s) in the word", strlen(string));
}
}
Thanks
Xiang