3
When I call the call malloc
, I only had space for one char
, but it works for words of any size, so I got confused
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char *palavra;
palavra = malloc(sizeof(char));
printf("Informe a palavra\n");
scanf("%s", palavra);
printf ("%d", conta_vogais(palavra));
}
int conta_vogais (char* s){
int tamanho = strlen(s);
char *vogais = {"aeiouAEIOU"};
int i, j, count = 0;
for(i = 0; i < tamanho; i++){
for(j = 0; j < strlen(vogais); j++){
if(s[i] == vogais[j]){
count++;
continue;
}
}
}
return count;
}
When you allocate, it reserves the amount in the String type memory, and if you only enter one word it will work, now if you put space and enter the second word it will not work. Check this link out: * Source: https://www.ime.usp.br/~elo/Introducaocomputacao/Caracter.htm
– Darlan