第1个回答 2017-12-28
挺简单的基础C语言题目,思路大概如下
char *myfunc(char *p, int size)
{
char *tmp_p1 = p;
char *new_p, *tmp_p2;
new_p = malloc(size*sizeof(char));
tmp_p2 = new_p;
while(*(tmp_p1++)!='\0')
{
// 把tmp_p1指针移到字符串的末尾
}
while(tmp_p1-- != p)
{
*(tmp_p2++) = *(tmp_p1);
}
return new_p;
}
大概思路就是让一个临时指针跑到p字符串的末尾,然后定义新的指针不断自增,而p的临时指针不断自减,把值赋给新的指针。
代码没有执行过,关于++和--可能会有一位的误差,需要自己调试一下。
第2个回答 2017-12-28
#include<stdio.h>
#include<string.h>
void daozi(char *s)
{
int i,j,c,temp;
c=strlen(s)-1;
for(i=0,j=c;i<j;i++,j--)
{
temp=*(s+j);
*(s+j)=*(s+i);
*(s+i)=temp;
}
}
int main()
{
char a[20];
scanf("%s",&a);
daozi(a);
printf("%s",a);
return 0;
}本回答被提问者采纳
第3个回答 2017-12-28
#include "stdio.h"
void reverse(char* a,int len){
int i,j,temp;
for (i=0,j=len-1;i<j;i++,j--){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
main()
{
char a[100];
scanf("%s",a);
reverse(a,strlen(a));
printf("%s",a);
}