this is my first program in this language ever (besides 'hello
world'), can i get a code critique, please? it's purpose is to read
through an input file character by character and tally the occurrence
of each input character. it seems to compile and run, so i'm looking
for the opinions of old-timers here plz.
/*
* File: occurrenceTally.cpp
* Author: matthew
*
* Created on July 9, 2008, 6:15 PM
*/
#include <stdlib.h>
#include <fstream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argCount, char** argvArray) {
printf("filename ");
printf("%s",argvArray[1]);
printf("\n");
ifstream OpenFile(argvArray[1]);
char inputCharacter;
int characters[256];
int i;
for (i = 1; i < 256; i++) {
characters[i]=0;
}
while(!OpenFile.eof())
{
OpenFile.get(inputCharacter);
//printf("%c",inputCharacter);
characters[int(inputCharacter)]++;
}
OpenFile.close();
for (i = 32; i < 126; i++) {
char outputCharacter;
outputCharacter = char(i);
if ( characters[i]>0 ) {
printf("%c ", outputCharacter);
printf("%i\n", characters[i]);}
}
return (EXIT_SUCCESS);
} 2 1294
Alf P. Steinbach wrote:
* matt:
>this is my first program in this language ever (besides 'hello world'), can i get a code critique, please? it's purpose is to read through an input file character by character and tally the occurrence of each input character. it seems to compile and run, so i'm looking for the opinions of old-timers here plz.
/* * File: occurrenceTally.cpp * Author: matthew * * Created on July 9, 2008, 6:15 PM */ #include <stdlib.h> #include <fstream.h>
This is not a standard header.
>#include <stdio.h> #include <string.h> #include <stdlib.h>
As a newbie you really should use C++ iostreams instead of C low-level i/o.
>int main(int argCount, char** argvArray) { printf("filename "); printf("%s",argvArray[1]);
argvArray[1] may not be initialized.
....
On Jul 9, 8:49*pm, Gianni Mariani <gi4nos...@mariani.wswrote:
Alf P. Steinbach wrote:
* matt:
this is my first program in this language ever (besides 'hello
world'), can i get a code critique, please? it's purpose is to read
through an input file character by character and tally the occurrence
of each input character. it seems to compile and run, so i'm looking
for the opinions of old-timers here plz.
/*
** File: * occurrenceTally.cpp
** Author: matthew
**
** Created on July 9, 2008, 6:15 PM
**/
#include <stdlib.h>
#include <fstream.h>
This is not a standard header.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
As a newbie you really should use C++ iostreams instead of C low-level i/o.
int main(int argCount, char** argvArray) {
* * printf("filename ");
* * printf("%s",argvArray[1]);
argvArray[1] may not be initialized.
...
also good. you guys rock! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Arthur Pratz |
last post by:
Hi all,
I have been working on this site for a while now.
I am posting on this newsgroup for honest reviews please.
I will be working on the store link with accepting credit cards online. So
any...
|
by: Cynthia Turcotte |
last post by:
Hi all --
A client has hired me to, among other things, optimize her web site
for search engine submission. So being the dutiful SEO geek that I
am, I went through and optimized each and every...
|
by: Eric |
last post by:
There is a VB.NET critique on the following page:
http://www.vb7-critique.741.com/
for those who are interested. Feel free to take a look and share your
thoughts.
Cheers, Eric.
Ps: for those...
|
by: TC |
last post by:
Are there any good sites or forums for a web critique? I went to
alt.html.critique and it's pretty dead.
|
by: bowsayge |
last post by:
Inspired by fb, Bowsayge decided to write a decimal integer
to binary string converter. Perhaps some of the experienced
C programmers here can critique it. It allocates probably
way too much...
|
by: G Patel |
last post by:
I wrote the following program to remove C89 type comments from stdin
and send it to stdout (as per exercise in K&R2) and it works but I was
hoping more experienced programmer would critique the...
|
by: christopher diggins |
last post by:
I have posted a C# critique at
http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up
the following issues :
- unsafe code
- attributes
- garbage collection
-...
|
by: Warhawk012 |
last post by:
Hey all,
I've started a portal site for the Embroidery community (both
professional and hobbyist), and I'm looking for some site comments and
critique.
The site is at...
|
by: winston |
last post by:
I wrote a Python program (103 lines, below) to download developer data
from SourceForge for research about social networks.
Please critique the code and let me know how to improve it.
An...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |