This question already has answers here:
Closed 5 years ago.
Is the strrev() function not available in Linux?
(4个答案)
关于为什么我试图编译这段代码来检查文件中的一行代码时会收到警告的任何想法:
代码
(4个答案)
关于为什么我试图编译这段代码来检查文件中的一行代码时会收到警告的任何想法:
atadata
代码
#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;
}
最佳答案
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;
}
10-08 03:51