I'm learning how the functions work with c, and I was doing this exercice that must count the number of vocals in a string. The problem is that always outputs 4199835 vocals.
Here it is the code (Working on windows 10, and compiler devc++):
#include <stdio.h>
#include <string.h>
char cadena[100];
int vocals();
int voc,i;
int main(){
fgets(cadena, sizeof(cadena),stdin);
strtok(cadena,"\n");
vocals(cadena);
printf("Hi ha %d vocals",vocals);
}
int vocals(char string[100]){
for (i=0;i<=strlen(string);i++){
switch(string[i]){
case 'a':
voc++;
break;
case 'e':
voc++;
break;
case 'i':
voc++;
break;
case 'o':
voc++;
break;
case 'u':
voc++;
break;
}
}
return voc;
}