implicit declaration of function ‘strrev’
19,309
Solution 1
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.
Solution 2
char *strrev(char *str){
char c, *front, *back;
if(!str || !*str)
return str;
for(front=str,back=str+strlen(str)-1;front < back;front++,back--){
c=*front;*front=*back;*back=c;
}
return str;
}
Solution 3
Incase some of the other peices of code are hard to read or you do not know how to use pointers, here is a short script to reverse a string.
#include <stdio.h>
#include <string.h>
int main(void)
{
// Start here
char String1[30] = "Hello",reversed[30];
int i;
long int length = strlen(String1);
//Reverse string
for(i=0; i<length; ++i)
{
reversed[length-i-1] = String1[i];
}
printf("First string %s\n",String1);
printf("Reversed string %s\n",reversed);
// To here if you want to copy and paste into your code without making functions
return 0;
}
Related videos on Youtube

Author by
Sean O'Brien
Updated on June 04, 2022Comments
-
Sean O'Brien 6 months
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; }
-
Martin James about 8 yearsIs there a definition for it in string.h?
-
David C. Rankin about 8 yearsThere is no
strrev
unless you have written one. (then you need to include the header with your declaration) -
The Paramagnetic Croissant@SeanO'Brien You open a text editor, type in the necessary code, save it as a text file and compile it using a C compiler.
-
-
Manjunath N about 8 yearsThis link might be useful from Stack overflow stackoverflow.com/questions/8534274/…
-
Alex Reynolds about 8 yearsThat's the same link that is in my answer.
-
Manjunath N about 8 yearsOh! i didn't observe that's good solution actually.
-
pasignature over 2 yearsThis is punk of readable coding style. I love simplicity.
-
Harshit Gangwar 9 monthsWorks for me. !