given a string "programming" and find the first occurrence of the vowel and move the sequence of consonants preceding the first vowel to the end of the string
Sample input:
Str[]=programming
Sample output:
Updated string=ogrammingpr
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int getIndexFirstOccurrenceVowel(char Str[]){
int i;
for (i = 0;i< strlen(Str); ++i) {
if (tolower(Str[i]) == 'a' ||
tolower(Str[i]) == 'e' ||
tolower(Str[i]) == 'i' ||
tolower(Str[i]) == 'o' ||
tolower(Str[i]) == 'u') {
return i;
}
}
return -1;
}
int main() {
char Str[]="programming";
char StrNew[20];
int i;
int counter=0;
int index=getIndexFirstOccurrenceVowel(Str);
printf("%s\n\n",Str);
if(index!=-1){
for (i = index;i<strlen(Str); ++i) {
StrNew[counter]=Str[i];
counter++;
}
for (i =0;i<index; ++i) {
StrNew[counter]=Str[i];
counter++;
}
StrNew[strlen(Str)]='\0';
printf("%s\n\n",StrNew);
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment