/*
语言:c语言
内容:字符串翻转
*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 1024
int getstring(char** s)
{
char *tmp = NULL;
tmp = (char*)malloc(SIZE);
if (tmp == NULL) {
return -1;
}
fgets(tmp, SIZE, stdin);
*s = tmp;
return 0;
}
int overturnstring(char** s)
{
char *tmp = *s;
int i = 0;
for (i = strlen(tmp) - 1; i >= 0; i--)
{
printf("%c", *(tmp + i));
}
printf("\n");
return 0;
}
int freestring(char** s)
{
char *tmp = *s;
if (tmp == NULL)
{
return -1;
}
free(tmp);
return 0;
}
int main()
{
int ret = 0;
char *s = NULL;
ret = getstring(&s);
ret = overturnstring(&s);
ret = freestring(&s);
system("pause");
return 0;
}
二级指针作参数,字符串倒序输出,源代码
最新推荐文章于 2023-01-04 22:16:23 发布