473,836 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

code critique please.

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("filenam e ");
printf("%s",arg vArray[1]);
printf("\n");
ifstream OpenFile(argvAr ray[1]);

char inputCharacter;
int characters[256];
int i;
for (i = 1; i < 256; i++) {
characters[i]=0;
}
while(!OpenFile .eof())
{
OpenFile.get(in putCharacter);
//printf("%c",inp utCharacter);
characters[int(inputCharac ter)]++;
}
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);
}
Jul 10 '08 #1
2 1322
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("filenam e ");
printf("%s",arg vArray[1]);
argvArray[1] may not be initialized.

....
Jul 10 '08 #2
On Jul 9, 8:49*pm, Gianni Mariani <gi4nos...@mari ani.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("filenam e ");
* * printf("%s",arg vArray[1]);

argvArray[1] may not be initialized.

...
also good. you guys rock!
Jul 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1406
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 tips for making an online checkout would be helpful. I will be using Miva Merchant to do that. Thanks for your time, Mike Pratz http://www.chowardcompany.com
7
2238
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 page of the site, including a complete recoding of the homepage which she botched. Now after all of this work, she tells me that she wants to keep the home page as it is. I've gone on record telling her that I feel that she won't get the...
37
2118
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 on comp.programming, this may be off topic, but I've posted there because the critique was part of a discussion in that group.
19
2560
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.
9
2289
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 memory, but it should certainly handle 64-bit cpus :) #include <stdio.h> #include <stdlib.h> char * to_binary (unsigned long value) {
8
1690
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 layout/style/etc. Any comments will be helpful. Thank you. /* **************************************************** C89/90 COMMENT REMOVER
188
7270
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 - non-deterministic destructors - Objects can't exist on the stack - Type / Reference Types
2
2292
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 http://www.embuniverse.com/ If some of you can help me out and tell me if the site flows nicely, and whether or not the placement of the menu items is correct (fiddled
2
1123
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 example use of the program: promptpython download.py 1 240000 The above command downloads data for the projects with IDs between 1
0
9826
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10860
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10604
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6984
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5659
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5831
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.