我为什么要敲代码 2016-07-14 03:56 采纳率: 0%
浏览 1904

DEVC++程序调试问题,赋值串值,老出现程序已停止工作,是怎么回事,求指点

定义了一个串,然后对串的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; 

}

  • 写回答

2条回答 默认 最新

  • oyljerry 2016-07-14 06:42
    关注

    ch是字符串数组,需要用strcpy等来进行拷贝赋值。而不能直接赋值

    评论

报告相同问题?