need help with tricky string modyfication

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2007
Posts: 49
Reputation: DeathEvil is an unknown quantity at this point 
Solved Threads: 0
DeathEvil DeathEvil is offline Offline
Light Poster

need help with tricky string modyfication

 
0
  #1
Jul 29th, 2007
Let's assume that the 100th user inputs his name as: Jackson Michael.

I would like my prog to print to the file the reference, which would be combining the first letter of the lastname with all the consonants remaining after removing all vowels (a,e,i,o,u).

in case of Jackson it would be: JCKSN100

any ideas how to accomplish that? as of right know all the inputted names are in an array and each element is a plain string.

Thanks in advance
Last edited by DeathEvil; Jul 29th, 2007 at 1:51 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: need help with tricky string modyfication

 
0
  #2
Jul 29th, 2007
Perhaps begin with a function called 'isVowel()', which returns true or false, depending on the type of letter passed to it.

Then implement your own 'strcpy' like function, which makes use of isVowel()
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,046
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 178
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: need help with tricky string modyfication

 
0
  #3
Jul 29th, 2007
Originally Posted by Salem View Post
Perhaps begin with a function called 'isVowel()', which returns true or false, depending on the type of letter passed to it.

Then implement your own 'strcpy' like function, which makes use of isVowel()
I would convert all the characters to upper case first, using toupper()
Last edited by Aia; Jul 29th, 2007 at 2:47 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 49
Reputation: DeathEvil is an unknown quantity at this point 
Solved Threads: 0
DeathEvil DeathEvil is offline Offline
Light Poster

Re: need help with tricky string modyfication

 
0
  #4
Jul 29th, 2007
Thanks guys, I will try to make something out of it, but that sounds like a good starting point. If anyone alse has any suggestions, please feel free to input your thoughts
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,046
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 178
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: need help with tricky string modyfication

 
0
  #5
Jul 29th, 2007
Originally Posted by DeathEvil View Post
Thanks guys, I will try to make something out of it, but that sounds like a good starting point. If anyone alse has any suggestions, please feel free to input your thoughts
Given a string without undesirable characters like '\n', etc...

  1. *
  2. * abbr.c
  3. * Converts string to upper case and removes vocals
  4. */
  5. #include <stdio.h>
  6. #include <ctype.h>
  7.  
  8. int main( void )
  9. {
  10. char name[]= "Jackson100"; /* given string */
  11. int i = 0, x = 0; /* indexes */
  12. int len = strlen( name ) + 1;
  13.  
  14. /* Make string to upper case and removing vocals */
  15. for( i = 0; i < len; i++ )
  16. {
  17. switch( name[i] = toupper( name[i] ) )
  18. {
  19. case 'A':
  20. break;
  21. case 'E':
  22. break;
  23. case 'I':
  24. break;
  25. case 'O':
  26. break;
  27. case 'U':
  28. break;
  29. default:
  30. {
  31. name[x] = name[i];
  32. ++x;
  33. }
  34. }
  35. }
  36. printf( "%s\n", name ); /* for testing purposes */
  37.  
  38. getchar();
  39. return 0;
  40. }
  41.  
  42. /* output: JCKSN100 */
Last edited by Aia; Jul 29th, 2007 at 4:02 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 49
Reputation: DeathEvil is an unknown quantity at this point 
Solved Threads: 0
DeathEvil DeathEvil is offline Offline
Light Poster

Re: need help with tricky string modyfication

 
0
  #6
Jul 29th, 2007
Thanks man, by the time I checked I got ready almost the same thing except I used if instead of switch. Very much appreciated.

Best Regards
DeathEvil
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,046
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 178
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: need help with tricky string modyfication

 
0
  #7
Jul 29th, 2007
Originally Posted by DeathEvil View Post
Thanks man, by the time I checked I got ready almost the same thing except I used if instead of switch. Very much appreciated.

Best Regards
DeathEvil
You're welcome. I don't know if that is how professionals would do it,
but that's one way I would.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: need help with tricky string modyfication

 
0
  #8
Jul 29th, 2007
More homework on a plate, very disappointing

You should have waited more than 5 minutes to see what the OP could come up with before blurting out an answer.

So instead of the OP getting to practice the all important analytical and problem solving skills, they're going to have to try to practice them on the next problem instead (only that will be so much harder now).

Oh well, nevermind, no great loss I suppose.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 49
Reputation: DeathEvil is an unknown quantity at this point 
Solved Threads: 0
DeathEvil DeathEvil is offline Offline
Light Poster

Re: need help with tricky string modyfication

 
0
  #9
Jul 29th, 2007
Originally Posted by Salem View Post
More homework on a plate, very disappointing

You should have waited more than 5 minutes to see what the OP could come up with before blurting out an answer.

So instead of the OP getting to practice the all important analytical and problem solving skills, they're going to have to try to practice them on the next problem instead (only that will be so much harder now).

Oh well, nevermind, no great loss I suppose.
I appreciate the concern but like I mentioned before I came up with basically the same thing, only I used if statement instead of swicth.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: need help with tricky string modyfication

 
0
  #10
Jul 30th, 2007
So start posting what you have, instead of always posting these open ended questions which beg for spoon feeding.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC