I am trying to break from an infinite for loop, if the user has entered a blank line, but I want to continue if the user has entered a word.
here is code to show.

#include <iostream>
using namespace std;

int main( void )
{
	char szMessage[32];

	for(;;)
	{
		cout << "Enter a string: ";
		if(cin.get(szMessage, 32));
		{
			cin.ignore(INT_MAX, '\n');
			break;
		}
		else if(strcmp(szMessage , " "))
		{
			break;
		}

	}
	
	system("pause");
	return 0;
}

Also, why is there an error on the else if saying, error: expected a statement.

Thanks, for the help

First of all, please choose a proper title for your post.
Second, I'm not so sure this is what you wanted, but just give it a try:

#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;


int main( void )
{
	char szMessage[32];

	for(;;)
	{
		cout << "Enter a string: ";
		cin.getline(szMessage, 32);
		if(strcmp(szMessage, "") != 0)
		{
			// Do whatever you want here
			//cin.ignore(INT_MAX, '\n'); INT_MAX not define here
			cout << "Here...\n";
		}
		// If user doesn't type in anything, just break out
		// of the loop
		else
		{
			break;
		}

	}
	
	system("pause");
	return 0;
}

First of all, please choose a proper title for your post.
Second, I'm not so sure this is what you wanted, but just give it a try:

#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;


int main( void )
{
	char szMessage[32];

	for(;;)
	{
		cout << "Enter a string: ";
		cin.getline(szMessage, 32);
		if(strcmp(szMessage, "") != 0)
		{
			// Do whatever you want here
			//cin.ignore(INT_MAX, '\n'); INT_MAX not define here
			cout << "Here...\n";
		}
		// If user doesn't type in anything, just break out
		// of the loop
		else
		{
			break;
		}

	}
	
	system("pause");
	return 0;
}

Yes, that was exactly what I needed. Thanks so much, and sorry about not naming the title correctly, couldn't think of a title that would make sense. And thanks so much again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.