#include<stdio.h> #include<string.h> #include<stdlib.h> char* reverse(char *s) { int i=strlen(s); int j= i; char *ptr=(char*)malloc(strlen(s)*sizeof(char)); memset(ptr, 0, strlen(s)*sizeof(char)); i--; for(;i>=0 ;i-- ){ ptr[i] = *s; s++; } ptr[j] = '\0'; s=ptr; return s; } int main(){ char *str=(char*)malloc( 200*sizeof(char) ); scanf("%s", str); str = reverse(str); printf("%s", str); return 0; } 修改这个代码让这个代码变得很复杂,难以读懂
时间: 2024-04-27 14:25:40 浏览: 110
51黑论坛_嵌入式面试汇总.pdf
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* reverse(char* s) {
int i = strlen(s);
int j = i;
char* ptr = (char*)malloc(strlen(s) * sizeof(char));
memset(ptr, 0, strlen(s) * sizeof(char));
i--;
for (; i >= 0; i--) {
ptr[i] = *s;
s++;
}
ptr[j] = '\0';
s = ptr;
return s;
}
void* obfuscate(void* ptr) {
int* p = (int*)ptr;
*p = (*p ^ 0xdeadbeef) + 0x1337;
return ptr;
}
int main() {
char* str = (char*)malloc(200 * sizeof(char));
printf("Enter a string: ");
scanf("%s", str);
str = (char*)obfuscate((void*)reverse(obfuscate((void*)str))));
printf("Reversed string: %s\n", str);
free(str);
return 0;
}
阅读全文