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