char a[]="i love ios,i want an iphone5s"; int test=0; //记录有多少空格的变量 for(int i=0;i<strlen(a);i++){ if(a[i]==' '){ //判断是否等于空格 test++; } }printf("%d ",test); //输出