Jump to content

C Programmers! I need help bad


Recommended Posts

my assignment was to make a program that opens a program designated by the user. then print out that document and count the number of lines, commas, capital, "the"s, and numbers.

i am having trouble with my numbers. i am always counting under for some reason an i cant figure out why

// Matt Watkins

// Cecs 121-01

// Project 09

// Apr. 7, 2010

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main()

{

char input[50];

char genesis[300000];

int i = 0;

char x;

FILE*infile;

printf("Which File Do You Want To Process? ");

scanf("%s", &input);

int filename = ("%s", input);

infile = fopen(filename, "r");

if (infile==NULL)

{

printf("Unable to open %s \n", input);

printf("Goodbye \n");

system("pause");

return 0;

}

i = 0;

do

{

x = fgetc( infile );

genesis=x;

i++;

}while (! feof(infile) );

genesis = 0;

fclose(infile);

printf("\n%s \n", genesis);

int counter;

int counter1;

int comma;

int capital;

int line=1;

int the;

int number=0;

for(counter=0; counter<strlen(genesis); counter++)

{

if(genesis[counter]==44)

comma++;

if(genesis[counter]>= 65 && genesis[counter]<=90)

capital++;

if(genesis[counter]==10)

line++;

}

for(counter=0; counter<strlen(genesis); counter++)

{

if(genesis[counter]==32||genesis[counter]==10)

{

counter++;

if(genesis[counter]==116||genesis[counter]==84)

{

counter++;

if(genesis[counter]==104||genesis[counter]==72)

{

counter++;

if(genesis[counter]==101||genesis[counter]==69)

{

counter++;

if(genesis[counter]==32||genesis[counter]==10)

{

the++;

}

}

}

}

}

}

for(counter=0; counter<strlen(genesis); counter++)

{

if (genesis[counter]>47 && genesis[counter]<58)

{

counter++;

if (genesis[counter]>=1 && genesis[counter]<=47 || genesis[counter]>=58 && genesis[counter]<=240)

{

number++;

}

}

else

{

counter++;

}

}

printf("Number of Commas: %5d \n", comma);

printf("Number of Capitals: %3d \n", capital);

printf("Number of Lines: %6d \n", line);

printf("Number of the's: %6d \n", the);

printf("Number of Numbers: %6d \n", number);

FILE * counts;

counts = fopen("Counts.txt", "w");

if (counts==NULL)

{

printf("Unable to open Counts.txt \n");

}

else

{

for(i=0; i<1; i++)

{

fprintf(counts, "Number of Commas: %5d \n", comma);

fprintf(counts, "Number of Capitals: %2d \n", capital);

fprintf(counts, "Number of Lines: %6d \n", line);

fprintf(counts, "Number of the's: %6d \n", the);

}

fclose(counts);

}

system("pause");

return 0;

}

i have my number counting section highlighted in blue.

please help guys i cannot figure this out

we are using ASCII decimal characters.

also forgive me for the autformat. it doesnt look like that in my program window

Edited by IH8PunkRok

-Matt

2005 Dodge Magnum RT
JVC KD-AVX1

2 PPI S580.2

Obsidian Audio ST1 Horn Tweeters

PRV 8MB450s

Audio Legion 3500.1D

2 RE MT 18s

360 ah LiFePO4 Battery
SHCA 2/0

155.2 @ 29 hz



Kicker CVR 15's build
DD 3512e build
Mini T-Line Build
(6) 8s Build
Nightshade 15s Wall Build
Magnum AB XFL 12s Build
Newest Magnum Build

Link to comment
Share on other sites

is this actually C or c++. I just wanna make sure. if its c++ i can help, if not it will just confuse the both of us :)

if c++ you wanna #include <fstream> so you can pull the file from the user and then you can do your computations from their file using ifile and the extractor command, then use some if statements with counters and you will be all good.

If it is actually c++ i can write out the code for you and it will make more sense than that jargon up there^^^

If not, I apologize for the waste of text :) lol

Rowan University Electrical Engineering

LINK TO MY BUILDDDDD

Current Setup in my 00' Hyundai Accent:

Pioneer DEH-P6900UB

RE.6.5C AUDIO 500w 6.5" COMPONENT CAR SPEAKERS

Eclipse SE 6500 (6.5 coax in rear deck)

two Kicker C124's in a t-line tuned to 28.6Hz

Kenwood KAC-7204

US amps 1600.4 V2

Upcoming Build this summer:

T-Line enclosure for two C124's tuned to 28ish hz O_O

amp my speakers with a US amps 1600.4.

Second Skin Should be fun ^_^

Link to comment
Share on other sites

is this actually C or c++. I just wanna make sure. if its c++ i can help, if not it will just confuse the both of us :)

if c++ you wanna #include <fstream> so you can pull the file from the user and then you can do your computations from their file using ifile and the extractor command, then use some if statements with counters and you will be all good.

If it is actually c++ i can write out the code for you and it will make more sense than that jargon up there^^^

If not, I apologize for the waste of text :) lol

If you can't tell by looking at it that this is NOT c++, then you don't know enough to help.

Not to be a dick but it's true.

Link to comment
Share on other sites

If you can't tell by looking at it that this is NOT c++, then you don't know enough to help.

Not to be a dick but it's true.

That is true, but in c++ you can still use that shit and it will still work. I was just thinking that maybe he was getting some bad help from online forums or accidentally looked up the wrong thing. I have 0 experience with C, but a shit ton of C++. And tbh, i didn't read through his entire code. I only made it through his header and noticed he was missing any type of inclusion for a file system.

edit: now looking through his code, i do see his use of the oldstyle file system. I will now leave this thread lol.

Good luck Matt. Sorry I can't help.

Edited by sven6977

Rowan University Electrical Engineering

LINK TO MY BUILDDDDD

Current Setup in my 00' Hyundai Accent:

Pioneer DEH-P6900UB

RE.6.5C AUDIO 500w 6.5" COMPONENT CAR SPEAKERS

Eclipse SE 6500 (6.5 coax in rear deck)

two Kicker C124's in a t-line tuned to 28.6Hz

Kenwood KAC-7204

US amps 1600.4 V2

Upcoming Build this summer:

T-Line enclosure for two C124's tuned to 28ish hz O_O

amp my speakers with a US amps 1600.4.

Second Skin Should be fun ^_^

Link to comment
Share on other sites

OP. you know in linux you can use some simple bash commands to do all this. just saying :D

grep "the" /path/to/filename|wc

Wonderful isn't it? lol

Need an install? Hit me up.
[email protected]


Got car audio questions? Check here first!
Everything you need to know. =]

http://www.stevemeadedesigns.com/board/topic/83029-everything-you-need-to-know/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Who's Online   0 Members, 0 Anonymous, 1754 Guests (See full list)

    • There are no registered users currently online
×
×
  • Create New...