作业3

来源:互联网 发布:js显示数组内容 编辑:程序博客网 时间:2024/05/19 19:42
#include <iostream>    #include "string.h"    using namespace std;    int main()  {      char str[200];  cin.get(str, 100, '\n');   for(int i = 0, j = 0; str[i] != '\0';)  {  j++;      i++  }   for(int x = 0, y = 0; x <= j; x++)   {  if(str[x] == ' ' &&str[x + 1] != ' ')      {  y++;  }   }   cout << "There are " << y + 1 << " words in the line." << endl;    return 0;  }