implicit declaration of function ‘strrev’

Sean O'Brien picture Sean O'Brien · Oct 28, 2014 · Viewed 19.4k times · Source

Any ideas on why when I try to compile this code to check if a line from the file atadata I get the warning:

warning: implicit declaration of function ‘strrev’ [-Wimplicit-function-declaration]

CODE

#include <stdio.h>
#include <string.h>

int main(){
    char palindromes[100];
    char reverse[100];
    FILE *atadata = fopen("atadata","r");
    while (fgets(palindromes,sizeof(palindromes),atadata) != NULL){
        strcpy(reverse,palindromes);
        strrev(reverse);
        if( strcmp(atadata,reverse) == 0)
        fputs(atadata, stdout);
    }
    fclose(atadata);
    return 0;
}

Answer

Alex Reynolds picture Alex Reynolds · Oct 28, 2014

If you are compiling in Linux, then strrev() is not part of string.h. The linked question contains an answer linking to source for an implementation you can bring into your own code directly.