如何通过变量访问结构体成员,如代码:
struct j{
int a,b,c,d,e;
}n[10]
int main(){
char x[1]="/0";
scanf("%c",&x[0]);
//然后我想用x这个字符里的字符去访问j里的变量,比如x="a",那么就访问n[i].a,别用判断结构(if,case,switch)因为我要用链表
}
我本人穷的一匹,求
#大佬
帮助
如何通过变量访问结构体成员,如代码:
struct j{
int a,b,c,d,e;
}n[10]
int main(){
char x[1]="/0";
scanf("%c",&x[0]);
//然后我想用x这个字符里的字符去访问j里的变量,比如x="a",那么就访问n[i].a,别用判断结构(if,case,switch)因为我要用链表
}
我本人穷的一匹,求
#大佬
帮助
#include<iostream>
using namespace std;
struct j {
int arr[5] = {1,2,3,4,5};
}n[10];
int main() {
char x = 'a';
scanf("%c", &x);
printf("%d", n[0].arr[x - 'a']);
return 0;
}
#include<iostream>
#include<map>
using namespace std;
struct j {
map<char, int> mp;
}n[10];
int main() {
char x = 'a';
scanf("%c", &x);
printf("%d", n[0].mp[x]);
return 0;
}