Answer to Question #218069 in C for Hemambar

Question #218069

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-19T16:05:55-0400
#include <stdio.h>
#include <ctype.h>
#include <string.h>


int main() {
	
	char Str[]="programming";
	char strNewString[20];
	int i;
	int c=0;
	int index;
	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') {
				index=i;
				break;
		}
	}


	printf("Current string: %s\n",Str);
	if(index!=-1){
		for (i = index;i<strlen(Str); ++i) {
			strNewString[c]=Str[i];
			c++;
		}
		for (i =0;i<index; ++i) {
			strNewString[c]=Str[i];
			c++;
		}
		strNewString[c]='\0';
		printf("New string: %s\n\n",strNewString);
	}


	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