我正在編寫一個模擬程序,當(dāng)用戶選擇創(chuàng)建一個新的標(biāo)記時,用戶應(yīng)該輸入一個標(biāo)簽ID、標(biāo)簽的所有者和標(biāo)記所代表的對象。程序所做的只是跳過掃描所有者的命令,我不太清楚原因。我的代碼如下(函數(shù)在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貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個贊
第1點(diǎn)
%c
\n
scanf(" %c", &tag[i].owner); ^ | note the space
\n
第2點(diǎn)
%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 關(guān)注
- 685 瀏覽
添加回答
舉報(bào)
0/150
提交
取消