gpt4 book ai didi

c - 我对 int 数组有相同的结构问题

转载 作者:行者123 更新时间:2023-11-30 16:05:08 25 4
gpt4 key购买 nike

paxdiablo 给出了它使用 char 数组的先前答案。我可以知道如何使用 int 数组来处理下面相同的代码吗?

喜欢:

struct encode {
int code[MAX]; //instead char code[MAX]
} a[10];

int main() {
int i, j;
int x[] = {3,0,2,5,9,3,1};
//instead char x[] = {'3','0','2','5','9','3','1','\0'};
for(i = 0; i < 1; i++) {
for(j = 0; j < 7; j++) {
printf("%d", x[j]);
}
printf("\n");

a[0].code=x;
//strcpy(a[0].code, x); for char

}
printf("%d\n",a[0].code);
//printf("%s\n",a[0].code); for char
return 0;
}

就像show一样,这可以用于int数组吗?提前致谢。

最佳答案

请引用您上一个问题的答案 question on struct with char array

  • 使用memcpy复制整数数组元素。
  • 如果您想打印,请使用%d整数。

关于c - 我对 int 数组有相同的结构问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1912155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com