does char myStr[varLength]
work in C?
I have the following (code here):
int isVMin(char c){
return c == 'a' ||
c == 'e' ||
c == 'i' ||
c == 'o' ||
c == 'u' ||
c == 'y';
}
int isNum(char c){
return c>='0' && c<='9';
}
int removeChars(char str[]){ // removes all vowels, returns the digits number
int slen = strlen(str);
//char* res = malloc(sizeof(char)*slen+1);
char res[slen + 1]; /// <<<<<<<<<<<<<<<<<<<<<<<<<<<<< DOES IT WORK AS EXPECTED???
printf("\nthe initial is: '%s'\n", res);
int numCount = 0, j = 0;
for (int i = 0; i < slen; i++) {
if (isVMin(str[i]));
//str[i]= ' ';
else {
res[j++] = str[i];
if (isNum(str[i]))
numCount++;
}
}
res[j] = '\0';
printf("\nthe removed is: '%s'\n", res);
//str = res;
return numCount;
}
int main(){
char phrase[50];
gets(phrase);
int nb = removeChars(phrase);
printf("\nLa phrase '%s' contient %d digits", phrase, nb);
return 0;
}
The program compiles and work as expected. However I have doubts if this usage is legal in C...