Our aim is to connect students from campuses all over Delhi by making them aware of all Technical, Cultural, Management fests, workshops, Seminars organized by every college in Delhi.

Join Us Now

Program 33: Write a C++ program to count the number of words in a string.

using namespace std;

int main()
	int count=0,length=0;
	char str[100];
	cout<<"\nenter a string : ";

	for(int i=1;str[i]!='\0';i++)
		if(str[i]==' '&&str[i+1]!='\0')
	cout<<"\ntotal no of words in a string : "<<count+1;
	return 0;

If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.