Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-15-2003, 06:00 PM   PM User | #1
Xiang
New Coder

 
Join Date: Jul 2002
Location: Malaysia
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Xiang is an unknown quantity at this point
alpha & space

Dear sir,

Refers to the coding below. I want to acccept alpha from the users and display the length of string excluding space. But my program even can't detected the space and if I enter the non-alpha it still can accept. Why???

If I enter the non-alpha at the beginning and center of the string or word as below, it still display the string instead of it should display the "Error!" message???
#$abc or abc%2^de
#hello world

Furthermore, if I don't want users input the word within the space, what can I do? (If users given the word within the space I want to display the error message).

void main(void)
{
char string[100];
int idx, valid;
clrscr();

printf("Enter a sentence ");
gets(string);

idx=0;
while (string[idx] != '\0')
{ if (isalpha(string[idx]) && !isspace(string[idx]))
valid = 1;
else
valid = 0;
idx++;
}

if (valid==1)
{
printf("%s", string);
printf("\nThe length of the sentence is %i", strlen(string));
}
else
printf("Error!");


Best regards,

Xiang
Xiang is offline   Reply With Quote
Old 03-17-2003, 11:13 PM   PM User | #2
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
Could you give some input and output so that we might better understand?

Jason
Jason is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:51 AM.


Advertisement
Log in to turn off these ads.