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(inpu t)))) to transfer the result of three conversions to an output string?
Thanx in advance! :)
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(
Thanx in advance! :)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I see that you've posted the question twice.
Please refer:
https://www.experts-exchange.com/questions/20557404/C-basic-string-handling.html
Mayank.
Please refer:
https://www.experts-exchange.com/questions/20557404/C-basic-string-handling.html
Mayank.
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! :))
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! :))
ASKER
Mayank: It was a mistake, if an admin could please delete the double post, I'd appreciatte it. Sorry!
ASKER
Clear response, as usual around here :)
Glad to help, and good luck :)
Marc
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.
https://www.experts-exchange.com/questions/20557404/C-basic-string-handling.html
Mayank.
As for your second question,
strcpy(output,conv3(conv2(
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