IH8PunkRok Posted April 20, 2010 Report Share Posted April 20, 2010 (edited) 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 April 20, 2010 by IH8PunkRok Quote -Matt2005 Dodge Magnum RTJVC KD-AVX1 2 PPI S580.2 Obsidian Audio ST1 Horn Tweeters PRV 8MB450s Audio Legion 3500.1D 2 RE MT 18s 360 ah LiFePO4 BatterySHCA 2/0 155.2 @ 29 hzKicker CVR 15's buildDD 3512e buildMini T-Line Build(6) 8s BuildNightshade 15s Wall BuildMagnum AB XFL 12s BuildNewest Magnum Build Link to comment Share on other sites More sharing options...
treossi Posted April 25, 2010 Report Share Posted April 25, 2010 i can helpz Quote Team sundownWESTCOASTSPL.COM we're throwing dbdrag events very soon visit the website for details Link to comment Share on other sites More sharing options...
sven6977 Posted April 25, 2010 Report Share Posted April 25, 2010 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 Quote 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 More sharing options...
Sanitarium Posted April 25, 2010 Report Share Posted April 25, 2010 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. Quote Link to comment Share on other sites More sharing options...
sven6977 Posted April 25, 2010 Report Share Posted April 25, 2010 (edited) 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 April 25, 2010 by sven6977 Quote 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 More sharing options...
Sanitarium Posted April 25, 2010 Report Share Posted April 25, 2010 OP. you know in linux you can use some simple bash commands to do all this. just saying grep "the" /path/to/filename|wc Quote Link to comment Share on other sites More sharing options...
Neo_frog Posted April 25, 2010 Report Share Posted April 25, 2010 OP. you know in linux you can use some simple bash commands to do all this. just saying grep "the" /path/to/filename|wc Wonderful isn't it? lol Quote 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 More sharing options...
treossi Posted April 26, 2010 Report Share Posted April 26, 2010 haha @ not knowing difference from c and c++ Quote Team sundownWESTCOASTSPL.COM we're throwing dbdrag events very soon visit the website for details Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.