1. 程式人生 > >抄了一個計算字符串個數的程序,一個很簡單的代碼。但是能看懂,也能掌握使用。原諒我菜,抽出一個小時看幾段代碼也好

抄了一個計算字符串個數的程序,一個很簡單的代碼。但是能看懂,也能掌握使用。原諒我菜,抽出一個小時看幾段代碼也好

ets 也好 字符 HERE get style lan pac 字符串個數

#include<stdio.h>main(){ char string[100]; int index,word=1; char blank; gets(string); if(string[0]==‘\0‘) { printf("there is no char!\n"); } else if(string[0]==‘ ‘) { printf("first char just is a blank!\n"); } else { for(index=0;string[index]!=0;index++) { blank=string[index]; if(blank==‘ ‘)
{ word++; } } printf("%d\n",word); } return 0; }

抄了一個計算字符串個數的程序,一個很簡單的代碼。但是能看懂,也能掌握使用。原諒我菜,抽出一個小時看幾段代碼也好