[C] 纯文本查看 复制代码#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
int WorkStr(const char *str1, char **OutStr, int len)
{
int ret = 0;
char *p1 = NULL, *p2 = NULL;
char *tmp = NULL;
char tmp_value;
if (NULL == str1 || 1 >= len)
{
ret = -1;
printf("func WorkStr err: %d \n", ret);
return ret;
}
tmp = (char *)malloc(sizeof(char) * len);
strcpy(tmp, str1);
p1 = tmp;
p2 = p1 + strlen(tmp) - 1;
while (p1 < p2)
{
tmp_value = *p1;
*p1 = *p2;
*p2 = tmp_value;
p1++;
p2--;
}
*OutStr = tmp;
printf("tmp:%p\n", tmp);
return ret;
}
int main()
{
char *str1 = "abcd";
char *str2;
int rv = 0;
int len = strlen(str1);
rv = WorkStr(str1, &str2, len);
if (-1 == rv)
{
return rv;
}
printf("%s\n", str2);
printf("str2:%p\n", str2);
free(str2);
system("pause"); return rv;
}