Unsigned Char 位访问,确定 char 是否由 1 和 0 组成
嘿,我需要一些有关无符号字符位访问的帮助。我需要测试以确保“通道”(无符号字符(UCHAR))的长度为 6 位(我有),并且输入的数字实际上是二进制数(又名 1 或 0)。我不知道如何访问它。任何帮助都会很棒!
void binEnter(void *channel){
int i;
for (i=0; i<6; i++) {
redo:
printf("Enter binary value for Channel %d: ",i);
scanf("%s",(UCHAR *)channel);
if (strlen(channel)!=6) {
printf("Error entry must be six digits!\n");
goto redo;
}
}
}
Hey I need a little help with unsigned char bit access. I need to test to ensure that "channel" which is an unsigned char (UCHAR) is 6 digits long (i have that) and that the the number enter is infact a binary number (aka 1s or 0s). I at a loss for how to access it. Any help would be great!
void binEnter(void *channel){
int i;
for (i=0; i<6; i++) {
redo:
printf("Enter binary value for Channel %d: ",i);
scanf("%s",(UCHAR *)channel);
if (strlen(channel)!=6) {
printf("Error entry must be six digits!\n");
goto redo;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
做一个循环来检查每个数字。
您也可以使用
strtol(3)
并检查结果endptr
来查看是否有 6 位数字。Make a loop to check each digit.
You could also just use
strtol(3)
and check the result inendptr
to see if you got a 6-digit number.