#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; } 整理这个代码格式,使其美观容易阅读
时间: 2024-04-27 21:25:37 浏览: 210
#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;
}
阅读全文