65,210
社区成员
发帖
与我相关
我的任务
分享
# include <iostream.h>
# include <string.h>
void revert(char* str)
{
int n = strlen(str);
int i = 0;
char c;
for(i = 0 ; i <=(n/2) ; i++)
{
c = str[i];
str[i] = str[n-i-1]; str[n-i-1] = c; //该行调试不过,说什么越界~!
}
}
void main()
{
char *s = "ABCDEFG"; //是const变量,改成char s[]="ABCDEFG";
revert(s);
cout < <s;
}
# include <iostream>
# include <cstring>
using namespace std;
void revert(char* str)
{
int n = strlen(str);
int i = 0;
char c;
for (i = 0 ; i <=(n/2) ; i++)
{
c = str[i];
str[i] = str[n-i-1];
str[n-i-1] = c;
}
}
int main()
{
//char *s = "ABCDEFG"; //这里s指向常量区,不能修改
char s[] = "ABCDEFG"; //这里s分配在栈上,能修改其数据
revert(s);
cout << s << endl;
return 0;
}
# include <iostream>
# include <string.h>
using namespace std;
void revert(char* str)
{
int n = strlen(str);
int i = 0;
char c;
for(i = 0 ; i <=(n/2) ; i++)
{
c = str[i];
str[i] = str[n-i-1];
str[n-i-1] = c; //该行调试不过,说什么越界~!
}
}
void main()
{
char *s = "ABCDEFG";
revert(s);
cout <<s;
}