Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
CODE CHECK.!!
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Alf P. Steinbach, post: 3421617"] * samoukos: Please don't shout. Note that ASCII does not define any greek characters: presumably what you mean is using an encoding with one byte per character. Also, it doesn't seem like the program counts words, but character instances (e.g. number of occurences of 'A' in the text). Indentation is a good idea. E.g. add four spaces at the start of lines inside { and }. These variables should most probably be declared locally where they're used. It's a good idea to use consistent naming convention. I.e. numberUsed or number_used, not NumberUsed which is unlike the others. From the code below this is used to store the text. A std::string is much more safe and convenient. If sum[i] is the number of occurences of the character encoded as value i, then the above array can't count occurences of a character encoded as 255, because valid indices range from 0 to 254, inclusive. The assumption of no 255-characters may be valid, or not. [i] Level 1 correction: use symbolic names for "magic" numbers such as 1000000, and use descriptive names such as "text" rather than "alpha". Level 2 correction: use a locally declared loop variable, for( int i = 0; i < textBufferSize; ++i ) { text[i] = 0; } Level 3 correction: do this initialization in the declaration, size_t const textBufferSize = 1000000; char text[textBufferSize] = {0}; Level 4 correction: use a std::string instead, std::string text; [i] Level 1, 2 and 3 corrections as noted for 'alpha' above. Rest snipped, I think the above comments enough for now. Cheers & hth., - Alf[/i][/i][/i][/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
CODE CHECK.!!
Top