Warning: implicit declaration of Function ːstrlen' [-Wimplicit-Function-declaration]

Asked

Viewed 889 times

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){

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 these, you are forgetting the null terminator. Therefore, the arrays should have 2 positions. However, you don’t even need these arrays (and with that, you won’t need the terminators either) because that’s 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')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.