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

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()

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()

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

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 */

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

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.

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.

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.

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.:)

So start posting what you have, instead of always posting these open ended questions which beg for spoon feeding.

ok yesterday I have ran into a little trouble. The stub alone was working great but now when I externalized the function, i cannot get the desired output. I have already tried many things but I suspect it has something with passing the arrays into the function. Again, I'm able to compile the program and run it, it's the output of this function that is not correct.

void Find_Reference_Code(FILE *report, char last_name[MAXA][FL], int i, int i2, int index[MAXA])
{

        // FL is defined as 10
	int x = 0, x2 = 0; int len, check_num = 100;

	len = strlen( last_name ) + 1;

	//let's assume the last_name calling element is Jackson

	printf("before cases\n %s", last_name); // shows "Jackson" like it supposed to
   for( x = 0; x < len; x++ )
   {
      switch(last_name[x][FL] = toupper( last_name[x][FL] ) )
      {
         case 'A':
            break;
         case 'E':
            break;
         case 'I':
            break;
         case 'O':
            break;
         case 'U':
            break;
          default:
         {
			last_name[x2][FL] = last_name[x][FL];
            ++x2;
			
         }
      }

   }
   	  printf( "after cases\n%s", last_name); // shows Jackson100, instead of JCKSN100 so the the whole stich is skipped. 
	  printf("%d\n", check_num);
	  check_num++;
}

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]);

Thanks for the reply Salem.
After compiling the code below the only warning I'm getting is for converting float to short int (len is getting demoted). After those slight modifications after inputting "Jackson" I'm getting y100
which clearly indicates that the last name is not processed in switch i suppose. How can I change the processing from columns to rows? or where I can read about it? a link would be great if you have one.

Thanks

void Find_Reference_Code(FILE *report, char last_name[MAXA][FL], int i, int i2, int index[MAXA])
{

	int x = 0, x2 = 0; int len, check_num = 100;

	len = strlen( last_name[x] ) + 1;



	fprintf(report, "   before cases: %s\n", last_name);  //prints Jackson
   for( x = 0; x < len; x++ )
   {
      switch(last_name[x][FL] = toupper( last_name[x][FL] ) )
      {
         case 'A':
            break;
         case 'E':
            break;
         case 'I':
            break;
         case 'O':
            break;
         case 'U':
            break;
          default:
         {
			last_name[x2][FL] = last_name[x][FL];
            ++x2;
			
         }
      }

   }
   fprintf(report, "   after cases :%s%d\n", last_name[x], check_num); // prints y100
	  check_num++;
}

Read my post again.
All those references to last_name[x][FL] in the code body are out of bounds.

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] ) )

thank you for all the help; I got it to work, but as it turns out I cannot do it that way because later on I'm referring to the last name string and I need it as a whole. Then it hit me that the best way to do it, is to assign the actual last name string to a temporary string, take off the vowels from the temporary sting, print it, and that way the original last name would be untouched. This is how I attempted to do it, but the program prints some trash. I'm sure this is assigning problem, so if anyone could point out how to assign it.

void Find_Reference_Code(FILE *report, char last_name[MAXA][FL], int i, int i2, int index[MAXA], short int check_number)
{

	char ref[] = {last_name[index[i2]]};
	int x = 0, x2 = 0; int len;

	len = strlen( ref ) + 1;

   for( x = 0; x < len; x++ )
   {
      switch( ref[x] = toupper( ref[x] ) )
      {
         case 'A':
            break;
         case 'E':
            break;
         case 'I':
            break;
         case 'O':
            break;
         case 'U':
            break;
          default:
         {
			ref[x2] = ref[x];
            ++x2;
			
         }
      }
   }
   fprintf(report, "*   Reference: %.10s%d\n", ref, check_number);

never mind, I finally got it to work by using strcpy to copy last_name[index[i2]] to ref.

Thanks a bunch to everyone!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.