| | |
Switch logic error
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 91
Reputation:
Solved Threads: 0
Hey guys I am just wondering why the following code gives the wrong number of characters from a file when the character count is the default? Thanks.
C++ Syntax (Toggle Plain Text)
void main() { int blank_count = 0; int char_count = 0; int sentence_count = 0; char ch; ifstream iFile("c:\test.txt"); if (! iFile) { cout << "Error opening input file" << endl; } while (iFile.get(ch)) { switch (ch) { case ' ': blank_count++; break; case '.': sentence_count++; break; default: char_count++; break; } } cout << "There are " << blank_count << " blanks" << endl; cout << "There are " << char_count << " characters" << endl; cout << "There are " << sentence_count << " sentences" << endl; }
![]() |
Similar Threads
- Logic error? (C++)
- Erm, logic error?! (C++)
- program w/ switch AND nested if. six error messages (C++)
- How to Return Multidimensional Arrays (C++)
Other Threads in the C++ Forum
- Previous Thread: KEy board event trapping and manipulation
- Next Thread: Hmm Im stuck on this....
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






