If anyone can take a couple minutes to help me out it would be greatly appreciated. Right now, the counters for the frequency of the phrase "ing" in the beginning, middle, and end of a word are well into the thousands, even if "ing" isn't even present in the input. It might not be that big of a problem, I'm just really new to this and trying to figure it out.
Code:
char current,char1,char2,char3,char4,char5;
int anum,num,letter,wcount,starting,ending,middle,ingcount,anum3count,prevalue; // variable types
anum = 0;
num = 0; // variable values
letter = 0;
wcount = 1;
char1 = '#';
char2 = '#'; // set all char variables to '#' so that they fill in one at a time
char3 = '#';
char4 = '#';
char5 = '#';
printf("Enter text ending with a '#' symbol. \n");
scanf("%c",¤t); //reads the first one
if (current == ' ')
prevalue = current;
while (current != '#') //one while loop to test for everything
{
if ((current >= '.') && (current <= '~')) //searches alphanumeric characters
anum +=1;
if ((current >='0') && (current <='9')) // if the ASCII code signifies a number
num +=1;
if ((current >= 'A') && (current <= 'z')) // if the ASCII code signifies a letter
letter += 1; // adds one letter
if (char1 == '#')
char1 = current;
else
if (char2 == '#')
char2 = current;
else
if (char3 == '#')
char3 = current;
else
if (char4 == '#')
char4 = current;
else
if (char5 == '#')
char5 = current;
if ((char1 == 'i') && (char2 == 'n') && (char3 == 'g')) //searches for frequency of 'ing', stores in 'ingcount'
ingcount += 1;
if ((char1 == ' ') && (char2 == 'i') && (char3 == 'n') && (char4 == 'g')) //searches for words that start with 'ing', stores in 'starting'
starting += 1;
if ((char1 == 'i') && (char2 == 'n') && (char3 == 'g') && (char4 == ' ')) //searches for words that end with 'ing', stores in 'ending'
ending += 1;
if ((char1 != ' ') && (char2 == 'i') && (char3 == 'n') && (char4 == 'g') && (char5 != ' ')) //searches for words that have 'ing' in them, stores in 'middle'
middle += 1;
if ((char1 >= '.') && (char1 <= '~'))
if ((char2 >= '.') && (char2 <= '~')) //searches for three alphanumerics in a row
if ((char3 >= '.') && (char3 <= '~'))
anum3count += 1; //if it finds a set of three, it adds one to the counter
char1 = char2;
char2 = char3; //shifts the values of the variables for the next loop
char3 = char4;
char4 = char5;
scanf("%c",¤t); //reads the next one
if (char5 != '#')
char5 = current; //sets char5 to the new variable since the rest were moved back one.
if ((prevalue == ' ') && (current != ' '))
wcount += 1; //checks to see if there is a space and then a non-space character (start of a new word)
if (current == ' ')
prevalue = current; // if current is a space