#include<stdio.h>
#include<string.h>
#include <malloc.h>
void test(char*,char * &bingo);
int main(void)
{
char line[30];
puts("Enter strings");
gets(line);
int n;
n=strlen(line)-1;
char *bingo=(char *)malloc((n+1)*sizeof(char));
puts(bingo);
printf( "The line entered was: %s\n", line );
test(line,bingo);
puts(bingo);
free(bingo);
return 0;
}
void test(char*ptr,char * &bingo)
{
int i;
char *p=bingo;
for(i=strlen(ptr)-1;i>=0;i--)//求出ptr的长度,然后利用指针,从尾巴指向头部,然后返回指针值、
{
*(p+(strlen(ptr)-1-i))=*(ptr+i);
}
}
//以下是运行结果
Enter strings
juyh
屯屯葺葺葺葺_?幤?
The line entered was: juyh
hyuj葺葺葺葺_?幤?
Press any key to continue