Answer to Question #217191 in C for Hemambar

Question #217191

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


1
Expert's answer
2021-07-14T13:06:56-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS