注册 登录
编程论坛 C++教室

请帮我看看为什么程序中的结果不对

lindayanglong 发布于 2008-07-17 16:17, 672 次点击
请帮我看看为什么程序中的结果显示ID不是我所设置的值
#include<iostream>
using namespace std;

const int namesize=20;
const int phonesize=10;
const int idsize=10;

struct employee
{
    char name[namesize];
    char phone[phonesize];
    int   ID[idsize];
};

void showmember(employee a)
{
       cout<<"officer's data is:"<<endl;
        cout<<"name:"<<a.name<<endl;
        cout<<"phone:"<<a.phone<<endl;
        cout<<"ID:"<<a.ID<<endl;
}
void changename(employee & a, char newname[])
{
    strcpy(a.name, newname);
    return;
}




int main()
{

        employee a={"abc", "456464", 646};
        employee b={"juopik", "6646", 4434};
    showmember(a);
    showmember(b);
    changename(a, "tom");
    cout<<"after change the name"<<endl;
    showmember(a);
    
    return 0;
}
5 回复
#2
linren2008-07-17 16:45
把“int   ID[idsize];”
换成“int   ID;”
#3
zhong07111012008-07-17 19:38
同意楼上的意见啊 啊
#4
lindayanglong2008-07-17 20:09
谢谢, 明白
#5
flyue2008-07-17 21:13
同意2#
#6
sunkaidong2008-07-17 21:14
数组必须有明确的大小。。。或者用动态数组
1