第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C跳過一個函數(shù)的命令?

C跳過一個函數(shù)的命令?

C C++
狐的傳說 2019-07-13 16:09:44
我正在編寫一個模擬程序,當(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格式說明符。它數(shù)數(shù)以前輸入的\n,通過按下進(jìn)入前一次輸入后的鍵。你想要的是

scanf(" %c", &tag[i].owner);
       ^
       |
    note the space

跳過任何類似字符的前導(dǎo)空格(包括\n)在實(shí)際輸入之前。

第2點(diǎn)[邏輯錯誤]

按照這里的代碼,掃描 a 輸入,您需要使用%s格式說明符。

因此,最后,您的代碼應(yīng)該如下所示

   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


查看完整回答
反對 回復(fù) 2019-07-13
?
鴻蒙傳說

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個贊

%c是字符的說明符,您要輸入的是字符串,而不是字符。見掃描文件..要使用的是字符串的%s說明符。


查看完整回答
反對 回復(fù) 2019-07-13
  • 2 回答
  • 0 關(guān)注
  • 685 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號