[問題] 請益getchar()
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
dev C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
問題(1)
ch的型態是char, getchar()回傳值是整數
ch = getchar() 這樣子的寫法為何正確?
問題(2)
編譯後,終端機畫面一開始可以輸入字元, 可是code沒有出現輸入字元的指令
例如像是 "scanf(%s, &char1);" 這種,
編譯器怎麼知道輸入的字元就是要 getchar 要讀進的字元?
還有語意不清煩請再提醒小弟, 我在修改, 謝謝!!
感謝板上高手解惑!!!!
餵入的資料(Input):
CALL ME HAL.
預期的正確結果(Expected Output):
DBMM NF IBM/
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
// cypher1.c -- alters input, preserving spaces
#include<stdio.h>
#include<iostream.h>
#define SPACE ' ' // that's quote-space-quote
int main()
{
char ch;
ch = getchar(); // read a character
while (ch != '\n') // while not end of line
{
if(ch == SPACE) // leave the space
putchar(ch); // character unchanged
else
putchar(ch + 1); //change other characters
ch = getchar(); // get next character
}
system("pause");
return 0;
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.174.123.106
→
09/09 14:05, , 1F
09/09 14:05, 1F
→
09/09 14:05, , 2F
09/09 14:05, 2F
推
09/09 14:19, , 3F
09/09 14:19, 3F
→
09/09 14:26, , 4F
09/09 14:26, 4F
※ 編輯: sheep922420 來自: 1.174.123.106 (09/09 14:30)
→
09/09 14:48, , 5F
09/09 14:48, 5F
→
09/09 15:05, , 6F
09/09 15:05, 6F
→
09/09 15:07, , 7F
09/09 15:07, 7F
→
09/14 13:41, , 8F
09/14 13:41, 8F