The issue after having debugged it was that ch has been assigned a random characters / numbers
(e.g. 1, 0..), before I get to enter any character, which resulted in stucked in WHILE loop.
Below is the code snippet:
Code:
// chcount.cpp
#include <iostream>
#include <conio.h> // for getche()
using namespace std;
int main()
{
int chcount = 0; // counts non-space characters
int wdcount = 1; // counts spaces between words
char ch = 'a'; // ensure it isn't '\r'
while( ch != '\r' ) //loop until Enter is typed
{
// ch = getchar(); // Read a character before I enter anything
ch = getche(); // Not running getche() function.
if ( ch == ' ' ) // if it's a space
wdcount++; // count it as a word
else // otherwise,
chcount++; // count a character
}
cout << "\nWords=" << wdcount << endl
<< "Letters=" << chcount-1 << endl;
return 0;
}
getche() did not process further while getchar() simply accept random characters / numbers (e.g. 1,0)
before I get to enter anything in.
I have tried other functions such as getc(stdin) & getch() & lookup similar resolutions
without success for a few hours.
I am running Eclipse C/C++ Neon.3 (4.6.3 - 20170314-1500)
with MinGW-w64 on Windows 10.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.