Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 10th, 2008, 04:05 AM
matt
Guest
 
Posts: n/a
Default 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("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  
Old July 10th, 2008, 04:55 AM
Gianni Mariani
Guest
 
Posts: n/a
Default Re: code critique please.

Alf P. Steinbach wrote:
Quote:
* matt:
Quote:
>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.
>
>
Quote:
>#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.
>
>
Quote:
>int main(int argCount, char** argvArray) {
> printf("filename ");
> printf("%s",argvArray[1]);
argvArray[1] may not be initialized.

....
  #3  
Old July 10th, 2008, 07:45 AM
matt
Guest
 
Posts: n/a
Default Re: code critique please.

On Jul 9, 8:49*pm, Gianni Mariani <gi4nos...@mariani.wswrote:
Quote:
Alf P. Steinbach wrote:
Quote:
* matt:
Quote:
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.
>
Quote:
Quote:
/*
** File: * occurrenceTally.cpp
** Author: matthew
**
** Created on July 9, 2008, 6:15 PM
**/
#include <stdlib.h>
#include <fstream.h>
>
Quote:
This is not a standard header.
>
Quote:
Quote:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
>
Quote:
As a newbie you really should use C++ iostreams instead of C low-level i/o.
>
Quote:
Quote:
int main(int argCount, char** argvArray) {
* * printf("filename ");
* * printf("%s",argvArray[1]);
>
argvArray[1] may not be initialized.
>
...
also good. you guys rock!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.