定义了一个串,然后对串的ch进行赋值,总会出现程序已停止工作,到底怎么回事,求指点。
#include
#include
#define maxsize 50
using namespace std;
typedef struct
{
char ch[maxsize];
int len;
} CHARS;
int main()
{
CHARS *S;
cout<<"please input a string: "<<endl;
cin>>S->ch;
S->len=strlen(S->ch);
cout<<"the S->ch is :"<<S->ch;
return 0;
}
ch是字符串数组,需要用strcpy等来进行拷贝赋值。而不能直接赋值
可以直接赋值的,我觉的应该是声明了一个CHARS类型的指针S,并没有对它赋初值,所以程序在运行的时候,内存出问题了。