字符串倒序问题,我下面写的这个字符串倒序函数怎么在运行时老出现内存访问冲突错误呢
下面的函数在运行到赋值语句 *head=*tail时报错,错误原因为:写入head指向的地址时发生访问冲突。
这到底是怎么回事呢???
谢谢帮助!
//将给定的字符串倒序
void strReverse(char * str)
{
char * head = str;
char * tail = str;
char temp;
if (NULL == str)
{
printf("parameter error!");
return;
}
//printf("%s \n", str);
while (*tail)
{
tail++;
}
tail--;
while (head < tail)
{
temp = *head;
*head = *tail; //此赋值语句运行时出现问题,
*tail = temp;
head++;
tail--;
}
//printf("%s \n", str);
}