473,781 Members | 2,335 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 1319
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
1401
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
2233
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
2114
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
2555
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
2283
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
1688
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
7255
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
2288
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
1118
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
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
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...
0
10139
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
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
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
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...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
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.