How to use the strcountc function in C

Asked

Viewed 521 times

0

Good afternoon, I’m not able to compile an exercise of Luis Damas' book C Language. The code is the same as the example but in the compilation the following errors occur:

||=== Build: Debug in prog0707 (compiler: GNU GCC Compiler) ===|
C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c||In function 'Separa':|
C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c|14|warning: implicit declaration of function 'strcountc'; did you mean 'strcspn'? [-Wimplicit-function-declaration]|
C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c|31|warning: return type defaults to 'int' [-Wimplicit-int]|
C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c||In function 'main':|
C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c|41|warning: implicit declaration of function 'wordupr'; did you mean 'wcsupr'? [-Wimplicit-function-declaration]|
C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c|41|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c|41|warning: format '%s' expects argument of type 'char *', but argument 3 has type 'int' [-Wformat=]|
c:\mingw\bin\..\lib\gcc\mingw32\8.2.0\..\..\..\..\mingw32\bin\ld.exe: obj\Debug\main.o||in function `Separa':|
C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c|14|undefined reference to `strcountc'|
c:\mingw\bin\..\lib\gcc\mingw32\8.2.0\..\..\..\..\mingw32\bin\ld.exe: obj\Debug\main.o||in function `main':|
C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c|41|undefined reference to `wordupr'|
c:\mingw\bin\..\lib\gcc\mingw32\8.2.0\..\..\..\..\mingw32\bin\ld.exe: C:\Users\wmazo\Documents\codigos\codigos_em_c\prog0707\main.c|41|undefined reference to `wordupr'|
||error: ld returned 1 exit status|
||=== Build failed: 4 error(s), 5 warning(s) (0 minute(s), 0 second(s)) ===|

Follow the code for analysis.

#include <stdio.h>
#include <string.h>
#define OP_SAIR "SAIR"

/*
* Coloca no Parâmetro Sobrenome a última palavra da string Nome.
* Em seguida retira essa palavra da string Nome colocando um '\0'
*
*/

void Separa(char *Nome, char *Sobrenome)
{
    int i,j;
    if (strcountc(Nome,' ')==0) /* Existe apenas uma ou zero palavras no nome */
    {
        Sobrenome[0]='\0';
        return;
    }
    /* Existe a garantia que há um sobrenome */

    for (i=strlen(Nome)-1,j=0 ; Nome[i]!=' ' ; )
        Sobrenome[j++] = Nome[i--];
    Sobrenome[j]='\0'; /* Terminar a string Sobrenome */
    Nome[i]='\0'; /* Retirar o sobrenome da String Nome */

    /* Como a string Sobrenome foi colocada do fim para o princípio é necessário invertê-la*/

    strrev(Sobrenome);
}

main()
{
    char Nome[100],Sobrenome[20];

    for (; ;) /* Equivalente a while (1) */
    {
        printf("Nome: ");
        gets(Nome);
        if (stricmp(Nome,OP_SAIR)==0) break; /* Sair do Programa */
        Separa(Nome,Sobrenome);
        printf("%s, %s\n",wordupr(Sobrenome),wordupr(Nome));
    }
}

I’m not understanding the error because the strcountc function by which I found it on the internet is in the string.c library. Does anyone know the reason for the error?

  • 1

    This strcountc function is not a standard <string. h> function. See the C language documentation which will find no reference to this function.

1 answer

0


Browser other questions tagged

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