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()
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
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()
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
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...
*
* abbr.c
* Converts string to upper case and removes vocals
*/
#include <stdio.h>
#include <ctype.h>
int main( void )
{
char name[]= "Jackson100"; /* given string */
int i = 0, x = 0; /* indexes */
int len = strlen( name ) + 1;
/* Make string to upper case and removing vocals */
for( i = 0; i < len; i++ )
{
switch( name[i] = toupper( name[i] ) )
{
case 'A':
break;
case 'E':
break;
case 'I':
break;
case 'O':
break;
case 'U':
break;
default:
{
name[x] = name[i];
++x;
}
}
}
printf( "%s\n", name ); /* for testing purposes */
getchar();
return 0;
}
/* output: JCKSN100 */
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
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.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
More homework on a plate, very disappointing :icon_frown:
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.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
So start posting what you have, instead of always posting these open ended questions which beg for spoon feeding.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
But your loop is processing a COLUMN of the array (an out of bound one at that), not a row.
> len = strlen( last_name ) + 1;
Please tell me that your compiler is generating warnings for this.
If it is, I would suggest some study and at least clean up all those problems.
Say for example that the 'i' parameter is the line you want to change.
Then you would have
len = strlen( last_name[i] ) + 1;
Then some switch(last_name[i][x] = toupper( last_name[i][x] ) )
Then at the end printf( "after cases\n%s", last_name[i]);
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Read my post again.
All those references to last_name[x][FL] in the code body are out of bounds.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
You are having a little bit of a problem with the subscripts in the multi-dimensional array. In order for you to reference them correctly, you need a nested loop.
int i, x;
for( i = 0; i < MAXA; i++ )
{
for( x = 0; x < len; x++ )
{
...Here goes the switch.
}
}
This statement will give you ALWAYS the length of the first string, by virtue of x = 0. It needs to be inside the first loop and before of the second loop, so you can obtain the length of the current working on string. Right now you are using the lenght of the first string for every case.
len = strlen( last_name[x] ) + 1;
You are ALWAYS trying to convert to upper case whatsoever lives at the last position of the multi-dimension, which doesn't contain any part of your inputed string.
switch(last_name[x][FL] = toupper( last_name[x][FL] ) )
The swith should be inside the second loop, and if you use the same
indexes it would be like
switch( last_name[i][x] = toupper( last_name[i][x] ) )
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218