Link to home
Start Free TrialLog in
Avatar of bass20
bass20

asked on

C basic string handling

Hello!

I need to do a quite simple thing in C; I have a string, and I have to add to it's end
the number of lowercase vowel sequences that end with an 'u'. For example,
"1ubAauedauB" turns into "1ubAauedauB2". Any hints?
Oh! And this is the 3rd function of a program; the previous 2 are already done and both return an altered string (as this one will). In the main() function, can I use something like: strcpy(output,conv3(conv2(conv1(input)))) to transfer the result of three conversions to an output string?

Thanx in advance! :)
Avatar of marcjb
marcjb
Flag of United States of America image

For adding on to the first string, use the 'strcat' function.  It will add one string onto another.

As for your second question,
strcpy(output,conv3(conv2(conv1(input))));
will work provided that:
1) conv1, conv2, and conv3 all take char* (an array of characters)
2) conv1, conv2, and conv3 all return a char*
3) input and output don't reference the same memory location (if they are 2 different strings, you are OK.  if they are pointers pointing at the same array, you are not allowed to do this.

Hope this helps,

Marc
Avatar of bass20
bass20

ASKER

Hum, I'll probably won't even have to use strcat as te inputted array will lose size allowing me to insert a new char at it's final index. My problem resides in how to detect the lowercase vowel sequences that end with an 'u'. As to the strcpy issue, thanks, I tought so :)
ASKER CERTIFIED SOLUTION
Avatar of marcjb
marcjb
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mayank S
I see that you've posted the question twice.

Please refer:

https://www.experts-exchange.com/questions/20557404/C-basic-string-handling.html

Mayank.
Avatar of bass20

ASKER

marcjb: It worked perfectly, but I ended up doing like this:

char *convM(char *s){
     int i=0, j=1, contador=0;
     char aux[10];
     
      for(i=0, j=1; i<50; i++)
          {
          if(s[j]=='u')
               {
               if(isLowerVowel(s[i])!=0)
               contador++;
               }
          j++;
          }
         
     sprintf(aux, "%d", contador);
     strcat(s,aux);    
     return(s);

Wouldn't have done without your inspiration, tough! Thanks for the sprintf :))) Got all three string convertions working together perfectly, so thanks a lot! :))
Avatar of bass20

ASKER

Mayank: It was a mistake, if an admin could please delete the double post, I'd appreciatte it. Sorry!
Avatar of bass20

ASKER

Clear response, as usual around here :)
Glad to help, and good luck :)

Marc
You have already accepted an answer but in case you want to try out another alternative, you can refer to:

https://www.experts-exchange.com/questions/20557404/C-basic-string-handling.html

Mayank.