lindayanglong 发表于 2008-7-17 16:17

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

请帮我看看为什么程序中的结果显示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;
}

linren 发表于 2008-7-17 16:45

把“int   ID[idsize];”
换成“int   ID;”

zhong0711101 发表于 2008-7-17 19:38

[tk02] [tk02] [tk02] [tk02] 同意楼上的意见啊 啊

lindayanglong 发表于 2008-7-17 20:09

谢谢, 明白

flyue 发表于 2008-7-17 21:13

同意2#

sunkaidong 发表于 2008-7-17 21:14

数组必须有明确的大小。。。或者用动态数组

页: [1]

编程论坛