C : Generating structure variable name from inputted number

标签 c

有没有什么方法可以把一个字母和一个数字连接起来,组成一个结构体变量名?我试图让我的程序为每个员工生成一个单独的结构变量,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/

相关文章:

android - 使用不同 NDL 编译的 C/C++ 代码的向前/向后兼容性?

c - 是否可以为多平台 : embedded or all operating systems? 编写 C 代码和库

c - 如何获得函数入口点?

c - 我的 C 代码 : wrong value output when I try to calculate Euler's number, e 有什么问题?

c - 为什么此代码会使 LED 发红光?

c - 如何在C中使用二维数组

c - 如何在C中逐行读取数字文本文件并将其存储到数组中?

c - Windows命名管道问题

clang-format:中断函数参数

c - Arduino 中断替代品