我正在编写一个模拟程序,当用户选择创建一个新的标记时,用户应该输入一个标签ID、标签的所有者和标记所代表的对象。程序所做的只是跳过扫描所有者的命令,我不太清楚原因。我的代码如下(函数在iotlib.cpp中):iotlib.cpp#include <stdio.h>#include <stdlib.h>#include <math.h>#define MAX 20struct 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[], int numEvents){
for(int i=0; i<numEvents; i++)
{
printf("Enter tag ID: ");
scanf("%i", &event[i].id);
printf("Enter node: ");
scanf("%c", &event[i].node);
printf("Enter distance from node as an integer number of feet: ");
scanf("%c", &event[i].dx);
}}void triangulationSimulate(struct tre event1, struct tre event2, int numEvents){
if(numEvents>1 && event1.id==event2.id)
{
printf("Node %c", event1.node);
for(int i=0; i<event1.dx; i++)
{
printf(" ");
}
printf("Tag %i", event1.id);
for(int i=0; i<event2.dx; i++)
{
printf(" ");
}
printf("Node %c", event2.node);
}}void getTagInfo(struct tagInfo tag){
printf("The tag with ID %i represents a/an %c belonging to %c", tag.id, tag.object, tag.owner);}
2 回答
慕神8447489
TA贡献1780条经验 获得超1个赞
第1点
%c
\n
scanf(" %c", &tag[i].owner); ^ | note the space
\n
第2点
%s
scanf("%s", tag[i].owner); // if tag[i].owner is char array
scanf(" %c", &tag[i].owner); // if tag[i].owner is a char, just in case
- 2 回答
- 0 关注
- 646 浏览
添加回答
举报
0/150
提交
取消