warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration] [closed]

0
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main()
{
    int j, vogais = 0, VOGAIS = 0, vogaistotais, tam;
    char a[1] = "a";
    char e[1] = "e";
    char i[1] = "i";
    char o[1] = "o";
    char u[1] = "u";
    char A[1] = "A";
    char E[1] = "E";
    char I[1] = "I";
    char O[1] = "O";
    char U[1] = "U";
    char texto[50];
    setbuf(stdin, NULL);
    printf("Insira um texto: ");
    fgets(texto,50,stdin);
    tam = strlen(texto);
    for (j=0; j<tam; j++){
        if (strcmp(texto[j], a) == 0){
            vogais = vogais + 1;
        }
        else{
            if (strcmp(texto[j], e) == 0){
                vogais = vogais + 1;
            }
            else{
                if (strcmp(texto[j], i) == 0){
                    vogais = vogais + 1;
                }
                else{
                    if (strcmp(texto[j], o) == 0){
                        vogais = vogais + 1;
                    }
                    else{
                        if (strcmp(texto[j], u) == 0){
                            vogais = vogais + 1;
                        }
                        else{
                            if (strcmp(texto[j], A) == 0){
                                vogais = vogais + 1;
                            }
                            else{
                                if (strcmp(texto[j], E) == 0){
                                    vogais = vogais + 1;
                                }
                                else{
                                    if (strcmp(texto[j], I) == 0){
                                        vogais = vogais + 1;
                                    }
                                    else{
                                        if (strcmp(texto[j], O) == 0){
                                            vogais = vogais + 1;
                                        }
                                        else{
                                            if (strcmp(texto[j], U) == 0){
                                                vogais = vogais + 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    printf("Vogais Minusculas: %d", vogais);
    printf("Vogais Maisuculas: %d", VOGAIS);
    printf("Vogais: %d", vogaistotais);
    return 0;
}
solucao.c:21: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
     tam = strlen(texto);
solucao.c:21: warning: incompatible implicit declaration of built-in function ‘strlen’ [enabled by default]
     tam = strlen(texto);
solucao.c:23: warning: implicit declaration of function ‘strcmp’ [-Wimplicit-function-declaration]
         if (strcmp(texto[j], a) == 0){
    
asked by anonymous 30.10.2018 / 04:58

1 answer

2

Use #include <string.h> instead of #include <strings.h> . Notice the difference between plural and singular.

However, your program has a lot of other errors:

char a[1] = "a";
char e[1] = "e";
char i[1] = "i";
char o[1] = "o";
char u[1] = "u";
char A[1] = "A";
char E[1] = "E";
char I[1] = "I";
char O[1] = "O";
char U[1] = "U";

In those days, you're forgetting the null terminator. Therefore, the arrays should have 2 positions. However, you do not even need these arrays (and you will not need the terminators either) because that is also wrong:

if (strcmp(texto[j], a) == 0)

Note that texto[j] is a caratectere, not a string. The goal here is to compare characters, so you should use this:

if (texto[j] == 'a')
    
30.10.2018 / 05:29