我正在嘗試使用指針向後重新排序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