c - 将字母数字值保存在作为结构一部分的数组中
问题描述
在下面的代码中,我定义了一个目前只有一个变量的结构:alphanumeric_code
. 该变量是一个包含 10 个值的数组,应该能够存储用户输入的任何字母数字值(即 abc123)。我的问题是:
- 如何存储用户使用辅助功能输入的值:
product_details()
? - 将字母数字数组定义为
int
最好的方法,对吗?根据另一个答案:我们可以将字母数字值存储在 int 数据类型中吗,似乎是这样。
非常感谢你们!:-)
#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]);
}
}
解决方案
推荐阅读
- javascript - TypeError:无法读取未定义的属性“过滤器”(实时搜索)
- python-3.x - 条件满足时跳出递归函数
- powershell - 我正在尝试使用 Powershell 替换字符,但出现很多错误
- reactjs - React Native - 当输入为空时禁用登录按钮
- python - 将 DataFrame 转换为时间序列
- django - 为什么应始终在 AWS SES 的 US-EAST-1 区域验证电子邮件?
- java - 获取模块 java.base 中所有类的 Class 对象
- visual-studio-code - Visual Studio Code 终端错误,无法运行代码。终端无法启动
- python - 如何从分类数据中提取小时、星期几?
- kubernetes - kubernetes 问题:运行时网络未准备好