[問題] 一題reversestring的問題
如題小弟寫了一題reverse string的練習題
有參考網路上的寫法
存了一個字串12345
想印出12345
跟54321
但無奈不知道為什麼印出來都是321而已
再請各位大大為小弟解惑
先謝過
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int GetStringValueAndReverse(char*);
void main()
{
char acString[]={"12345"};
int iResult=0;
//iResult=
GetStringValueAndReverse(acString);
}
int GetStringValueAndReverse(char* p)
{
char *t,temp,*end_p;
//int L=strlen(p);
t=(char*)malloc(sizeof(char)*strlen(p)+1);
strcpy(t,p);
printf("%s\n",t);
//printf("%d\n",L);
end_p=p+strlen(p)-1;
while(end_p>p)
{
temp=*p;
*p=*end_p;
*end_p=temp;
p++;
end_p--;
}
printf("%s",p);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.36.231.164
→
01/15 00:16, , 1F
01/15 00:16, 1F
→
01/15 00:16, , 2F
01/15 00:16, 2F
→
01/15 00:51, , 3F
01/15 00:51, 3F
→
01/15 08:30, , 4F
01/15 08:30, 4F
→
01/15 18:01, , 5F
01/15 18:01, 5F