×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

need help sorting letters in strings

need help sorting letters in strings

need help sorting letters in strings

(OP)
Am writing program that will continue to prompt user to enter a word of 5 letters or less until 'q' is entered to quit. Upon quitting, it will disply results from 4 functions :
1. total # of vowels (all words combined)
2. total # of conenants (same as above)
3. total # of words (simple counter)
4. total # of words ending with 'k'
Am using a while statement for the loop but can't get it to stop when {'q','\0'} is entered. Have assigned string to word[6] but it will take more than 5 letters and will not overwrite last word entered.
All books I have referenced have sorting examples with numbers not letters and all examples have string or array within source code.
Would appreciate any help that could be given.
Thanks to all
Ed

RE: need help sorting letters in strings

I think your main problem with failing to break out of the while loop is that you are checking for a lower case Q and not for an UPPERCASE Q..... You need to check for both. I prefer to use the Escape key for exiting because it is universally understood as an exit key by most users....
Below is some code I reuse quite often, because it checks for extended key codes:

int a;
a = getch(); /* Get key press and Add 256 if extended key*/
/* if your compiler doesn't have getch(), try getc() */
if (a == 0 ¦¦ a == 0xE0) { a = getch() + 0x100; }
switch ( a )
{
case 27: /* If escape key */
printf( "Exiting..." );
goto end;
case 328: /* If Up Arrow key */
break;
case 336: /* If Down Arrow key */
break;
default: /* Do other stuff */
break;
}

You get the idea....
If you put your words into a string ( a char array ) then your compiler's string functions should take care of the rest of the sorting functions for you with relative ease.
Also, since you want to be able to count the # of characters inputted and stop at a certain point, it is better to use getch() and echo the characters to the display via your program, than fight with gets()

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close