1. 程式人生 > >linux下的簡單程式設計——輸入一個字串,並輸出其個數

linux下的簡單程式設計——輸入一個字串,並輸出其個數

1、安裝虛擬機器(VMware12),安裝系統(Ubuntu14),安裝VMware Tools 2、為Ubuntu建立root使用者 3、在Ubuntu下安裝ssh服務,便於通過Xshell遠端訪問 4、通過cd /mnt/hgfs/shared/指令進入共享資料夾 5、通過mkdir length新建資料夾length 6、在length資料夾下,利用vi length.c指令建立c檔案 7、完成程式的建立、儲存並退出(i-進入編輯模式、:wq-儲存並退出、:!wq-強制退出) 8、程式如下: #nclude<stdio.h> int main() { char string[99],c; int i=0; scanf("%s",string); while( (c=string[i])!=’\0’) { i++; } printf(“There are %d words in this line.\n”,i); return 0; } 9、用gcc length.c指令進行編譯、並依提示進行修改 10、用./a.out指令執行結果檔案(可執行檔案a.out) 11、執行結果如下: aacd There are 4 words in this line.