首页 > 解决方案 > 将字母数字值保存在作为结构一部分的数组中

问题描述

在下面的代码中,我定义了一个目前只有一个变量的结构:alphanumeric_code. 该变量是一个包含 10 个值的数组,应该能够存储用户输入的任何字母数字值(即 abc123)。我的问题是:

非常感谢你们!:-)

#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int alphanumeric_code[10];
} product_structure;

void product_details(product_structure *user_details);

int main()
{
    product_structure user_details;

    product_details(&user_details);

    return 0;
}

void product_details(product_structure *user_details)
{
    int i = 0;

    puts("Please enter the alphanumeric value:");
    scanf("%d", &(user_details -> alphanumeric_code[10]));
    
    for (i = 0; i < 10; ++i)
    {
        printf("%c", user_details -> alphanumeric_code[i]);
    }
}

标签: carraysstruct

解决方案


推荐阅读