[問題] 計算輸入的字元數

看板C_and_CPP作者 (從心開始)時間12年前 (2011/11/29 00:34), 編輯推噓0(005)
留言5則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) DEVC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 我要算數出輸入的字有有幾個?? 餵入的資料(Input): ABCD 預期的正確結果(Expected Output): 4 錯誤結果(Wrong Output): 3 程式碼(Code):(請善用置底文網頁, 記得排版) #include <iostream> using namespace std; int main(){ int c=0,i=0; char s[20]; cout<<"Input :"<<endl; cin>>s[20] ; for(c;c<20;c++){ if(s[c]=='\b'){ break; }else i++; } cout<<"time:"<<i; system("pause"); return 0; } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.36.103.253

11/29 00:36, , 1F
糟...
11/29 00:36, 1F

11/29 00:42, , 2F
「修程式工人」準備現身~(∩_∩)
11/29 00:42, 2F

11/29 01:30, , 3F
剛好練習一下...
11/29 01:30, 3F

11/29 02:52, , 4F
cin>>s; if(s[c]=='\0'){ 改這2行...沒行號真慘
11/29 02:52, 4F

11/29 15:13, , 5F
strlen()
11/29 15:13, 5F
文章代碼(AID): #1EqxW5cK (C_and_CPP)