I am trying to code some sample practice problems for my C class but I ran into a segmentation fault error when trying to solve the following problem:
Write a function which is passed a c-string and returns the length of the longest subsequence of vowels contained in the string. Ex. if string is "AUOZZIE" function should return 3.
Attached is my code. Can anyone see a problem with it? Thank you in advance.
Code:
#include <stdio.h>
#include <ctype.h>
int vowel(char[]);
int main(int argc, char **argv)
{
char word[] = "AUOZKKUU";
printf("%d", vowel(word));
printf("\n");
return 0;
}
int vowel(char s[]){
int i=0;
int count=0;
int countMax=0;
int inst=0;
while(s[i]!='\0'){
START:
if(s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U' || s[i]=='Y'){
count++;
i++;
goto IS_NEXT_VOWEL;
}
IS_NEXT_VOWEL:
while(s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U' || s[i]=='Y'){
count++;
i++;
}
i++;
if(count>countMax)
countMax=count;
count=0;
goto START;
}
return countMax;
}