ZoeHwang_ 2017-02-18 07:18 采纳率: 100%
浏览 825
已采纳

C++入门级求帮忙看下代码哪里错了

#include
#include
#include
class Students{
private:
char name[10],num[5];
int age,score1,score2,score3,score4,score,i;
public:
void Init(char name_[],char num_[],int age_,int score1_,int score2_,int score3_,int score4_){
strcpy_s(name,name_);
strcpy_s(num,num_);
age=age_;
score1=score1_;
score2=score2_;
score3=score3_;
score4=score4_;
}
int output(){
score=(score1+score2+score3+score4)/4;
printf("%s,%d,%s,%d",name,age,num,score);
return 0;
}
};

int main()
{
char name[10],num[5];
int age,score1,score2,score3,score4;
Students s;
scanf_s("%s,%d,%s,%d,%d,%d,%d",&name,&age,&num,&score1,&score2,&score3,&score4);
s.Init(name,num,age,score1,score2,score3,score4);
s.output();
system("pause");
return 0;

}

用VS写的完整代码拷贝上来了,语法没有错误,但运行时说C++.1.exe 中的 0x6af7d22f (msvcr100d.dll) 处最可能的异常: 0xC0000005: 写入位置 0x002b0000 时发生访问冲突。

  • 写回答

1条回答 默认 最新

  • AlbertS 博客专家认证 2017-02-18 08:33
    关注

    注意使用scanf_s()函数的格式,如果其中有字符串。必须标明缓冲区大小,输入格式最好用空格分开
    将源代码改为scanf_s("%s %d %s %d %d %d %d", &name, 10, &age, &num, 5, &score1,&score2,&score3,&score4);即可

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型