-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvowel_reverse.c
60 lines (54 loc) · 1.05 KB
/
vowel_reverse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
LEARNING
You cannoth directly assign char to a character pointer. i.e you cannot do following
char *word;
char c = 'a';
word[i] =c; XXXXXXX
You need to make it a arr and the you can assigne the array to pointer.
char str[]="leetcode";
char *word =str;
char c = 'a';
word[i] = c [Correct]
*/
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
char str[]="leetcode";
char vlu[]={'a', 'e', 'i', 'o', 'u'};
bool check(char a)
{
for(int i=0; i<5; i++)
{
if(a == vlu[i])
{
return true;
}
}
return false;
}
void main(void)
{
int i,j=0;
char *word =str;
int len = strlen(word);
j=len;
for(i=0; i<len; i++)
{
if(check(word[i]))
{
while(j>i)
{
j--;
if(check(word[j]))
{
char temp= word[i];
word[i]= word[j];
word[j]=temp;
break;
}
}
}
}
printf("%s", word);
}