有没有什么方法可以把一个字母和一个数字连接起来,组成一个结构体变量名?我试图让我的程序为每个员工生成一个单独的结构变量,struct var 名称是他们的 ID 号。
struct employee {
int idnum;
char name[];
float salary;
}
int main(){
//get employee id
int id;
printf("enter id number: ");
scanf("%d", &id);
//makes it into a structure variable
struct employee /*'e' + id no.*/;
}
谢谢
最佳答案
没有。您能做的最好的事情就是将 id 映射到特定的结构实例。数组是处理少量数据的简单方法。 HashMap 是一种更通用的方法。
关于C : Generating structure variable name from inputted number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58741334/