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

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

在獲取之前輸入C.Scanf。問題

在獲取之前輸入C.Scanf。問題

C
森欄 2019-12-04 11:09:04
我對C很陌生,并且在向程序輸入數(shù)據(jù)時遇到問題。我的代碼:#include <stdio.h>#include <stdlib.h>#include <string.h>int main(void) {   int a;   char b[20];   printf("Input your ID: ");   scanf("%d", &a);   printf("Input your name: ");   gets(b);      printf("---------");   printf("Name: %s", b);      system("pause");   return 0;}它允許輸入ID,但只跳過其余的輸入。如果我這樣更改順序:printf("Input your name: ");   gets(b);      printf("Input your ID: ");   scanf("%d", &a);會的。雖然,我無法更改訂單,但我還是需要它。有人能幫我嗎 ?也許我需要使用其他一些功能。謝謝!
查看完整描述

3 回答

?
米脂

TA貢獻(xiàn)1836條經(jīng)驗 獲得超3個贊

scanf不會占用換行符,因此是的天敵fgets。如果沒有好的技巧,請不要將它們放在一起。這兩個選項都將起作用:


// Option 1 - eat the newline

scanf("%d", &a);

getchar(); // reads the newline character


// Option 2 - use fgets, then scan what was read

char tmp[50];

fgets(tmp, 50, stdin);

sscanf(tmp, "%d", &a);

// note that you might have read too many characters at this point and

// must interprete them, too


查看完整回答
反對 回復(fù) 2019-12-04
  • 3 回答
  • 0 關(guān)注
  • 595 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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