[筆記] gets() scanf()

常用EOF判別式

gets(input) != NULL
scanf(%s,input) != EOF

輸入格式

gets():一律視為一個字串
scanf():空格分離字串

換行

gets():輸入完畢自動換行
scanf():同上


Comments

2 responses to “[筆記] gets() scanf()”

  1. 現在更喜歡用 scanf(%s,input) = 1 這樣的寫法呢 =w=

    gets通常會被 compiler 警告,
    所以我更常用 fgets(str, size, stdin)
    不過 fgets(str, size, stdin) 會將 ‘\n’ 也讀進來

    其實我只是想借機會測試頭像有沒有用成功XD

    1. @NiwaSho Lin
      會去找gets的用法是因為剛有個題目會輸入含空格的字串,scanf的自動換行導致邏輯錯誤(汗

      你的頭像遠看有點…www

Leave a Reply

Your email address will not be published. Required fields are marked *