相关疑难解决方法(0)

C跳过一个函数的命令?

我正在编程模拟,当用户选择创建新标签时,用户应该输入标签ID,标签的所有者以及标签所代表的对象.程序正在做的只是跳过扫描所有者的命令,我不太清楚为什么.我的代码如下(函数在iotlib.cpp中):

iotlib.cpp

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 20

struct tagInfo
{
    char owner[MAX];
    char object[MAX];
    int id;
};
struct tre //TRE = Tag Read Event
{
    int id;
    char node[MAX];
    int dx;
};
void initTag(struct tagInfo tag[], int numTags)
{
    for(int i=0; i<numTags; i++)
    {
        printf("Enter the tag ID number: ");
        scanf("%i", &tag[i].id);
        printf("Enter owner of tag: ");
        scanf("%c", &tag[i].owner);
        printf("Enter the object the tag is attached to: ");
        scanf("%c", &tag[i].object);
    }
}

void generateTRE(struct tre event[], …
Run Code Online (Sandbox Code Playgroud)

c scanf

2
推荐指数
1
解决办法
666
查看次数

标签 统计

c ×1

scanf ×1