【发布时间】:2014-04-27 10:58:37
【问题描述】:
我是 C 新手。我有一个结构员工,如下所示:-
struct employee
{
char eid[100];
char name[100];
};
我想将此 eid 值分配为“EMP_1”、“EMP_2”等。每当任何员工输入其姓名时,其 id 都应动态生成,例如第一个员工的“EMP_1”和第二个员工的“EMP_2”。但我无法理解如何将整数值添加到 char 中。 我试过这样的
struct employee e;
char emp[20]="EMP_";
char id=(char)i; //Here i will be representing the number of employee like 1st or 2nd.
strcat(emp,id);
e.id=emp;
但它不起作用。任何其他建议如何将“EMP_1”“EMP_2”等值分配给 struct 的 id。
【问题讨论】:
-
1) 结构定义后缺少分号。 2)
struct emp是什么? 3)char[100] eid;-->>char eid[100]; -
@wildplasser struct employee 是一个员工类型的结构。
标签: c arrays string struct int