您的位置:首页 > 其它

有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student". 要求: 不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。

2017-05-05 17:21 731 查看
#include<assert.h>

void Swap(char*start,char*end)
{
while (start < end)
{
*start ^= *end;
*end ^= *start;
*start ^= *end;
start++;
end--;

}
}
void reverse(char *start, char*end)
{
/*while (start < end)
{
char*tmp = *start;
*start = *end;
*end = tmp;
start++;
end--;
}*/
Swap(start,end);

}
char*next_reverse(char*str)
{
assert(str);
char*start = str;
char*end = str;
while (*end != '\0')
{
while ((*end != ' ') && (*end != '\0'))
{
end++;
}

reverse(start, end-1);
if (*end == '\0')
break;
end += 1;
start = end;
}
return str;
}
int main()
{
char ret[] = "student a am i";
reverse(ret, ret + strlen(ret) - 1);
char* ret2 = next_reverse(ret);
printf("%s\n",ret2);
system("pause");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐