Quitting a While loop in C++ by entering a blank [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a loop in C++ that am stuck with, I want to end the loop by entering a blank, if a character is entered then the loop goes on. using VS2010

Presumably you have a variable storing a single character, and are wanting to stop the loop when someone enters a blank character (I'm going to presume space).
Just use a if statement and a break clause
while (true) {
// Get character here and put it into myChar variable
if ( myChar == ' ' )
{
break;
}
}
You could also put the check in the while condition if you have nothing else there. Another alternative would be a do-while loop.

Related

How can I stop a loop when an error occurs in imacros? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to fill my from four times.i take one csv file with four columns data.after inserting the first data one error is occurred.but imacros loop is not stoped.it leaves the first error and continuing other process.i want to stop the loop when error occured.
remove set !errorignore from your script

How to print a character code from char*? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm getting a character from a user input using getchar(), but instead of using cout to print the character I want to print the character code, like the one for Return, ESC, etc, so I can use in my code later to check using a if.
To do this you can cast the char to an int,
int charval = (int) mychar;
printf("%d\n", c); will show you the character code.
so I can use in my code later to check using a if.
You don't need to expicitly convert it to an int for that.
if(getchar() == char_code)
doSomething();
Cast the char as an int and print the int value.

Is this a Infinite loop? program finishes prematurely [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I´ve programmed a random writing program. That uses the markov algorithm. So it selects a order of letters, say [th] then go finding what appears most frequent after that using some randomness etc. But if the program selects a letter that has no "siblings". for example say right at the end of the file this symbol is [%] and it do not appear anywhere else in the file. What happens then is that the program just says "Finished running" it don´t even execute the coutcommand that prints out the string newText.
Why is this?
The rest of the code does basically some manipulation of arrays (adding etc..), to much code to post here.
for (int i = 0; i < fullText.length(); i++)
{
newText += getNext(currentWord, curWordPos, order);
}
cout << "Output: " << newText << endl;
Is this an Infinite loop?
No, it's not.

How to read the rest of a line after a specific string [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Please tell me how to write a function that checks every row in a file, and if it encounters a certain string (eg "set cookie"), it will output the rest of that line.
You probably want to use strstr. First, line by line, read into a variable (use cin.getline), then check the given line using strstr. If the output of strstr is not NULL, then process the line as you see fit.

C++ Program Required with arrays [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I want to write a program which will show the numeric value of odd, even & zero values in array. The problem is that when I input values in array, C++ compiler doesn’t view the result and finishes the output window . Is there any solution for this?
Assuming you mean why the console window closes, you can add cin.get() to the end.