我正在尝试使用指针向后重新排序C字符串。在我的程序中,我接受字符串,然后在for
循环中重新排列它。使用指针向后重新排列数组
例如,如果我输入Thomas
,那么它应该使用指针返回samohT
。
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int lengthString;
char name[256];
cout << "Please enter text: ";
cin.getline(name, 256);
cout << "Your text unscrambled: " << name << endl;
lengthString = strlen(name);
cout << "length " << lengthString << endl;
char* head = name;
char* tail = name;
for (int i = 0; i < lengthString; i++)
{
//swap here?
}
for (int j = lengthString - 1; j > -1; j--)
{
//swap here?
}
return 0;
}
我在这两个循环中遗漏了什么?
for(int i = 0; i
Lalaland
2011-12-23 19:40:32
我需要在这里使用指针 – mystycs 2011-12-23 19:45:02
你怎么需要修改就地char *? – 2011-12-23 19:54:50