作业3

#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;  
}  

你可能感兴趣的:(include,iostream,作业)