The explanation for my program:
int split_by_sentence(void)
Receives input from the user. A sentence with a period or multiple sentences, each sentence must have a period.
Writes the result to readtext.txt.
int main ()
Reads the readtext.txt file, sends a sentence/line at a time to the redefined_sentence function.
void redefined_sentence (char* sentence)
Receives the sentence and splits it into a word per line and writes the result to list.txt.
This word per line file is opened and read a line/word at a time in a while loop, till the file is all read.
The word is broken down into a single char and compared against a char array of consonants, to see if the word is a consonant.
If the letter is a consonant the result is written to intermediate.txt, only the consonant version of the word is written to the file.
When this happens, a integer is changed from zero to one.
In a different part of the while loop, it checks to see if the integer has changed, if it has the whole word is written to consonant_words.txt.
Now intermediate.txt and consonant_words.txt are closed and the while loop is finished.
Now intermediate.txt is opened again and the last word of the file is passed into the variable ‘last’.
Then intermediate.txt is closed.
Then intermediate.txt and consonant_words.txt are opened again.
In a new while loop, if the letters in ‘last’ is the same as the word in intermediate.txt, the whole word version from consonant_words.txt is written to comparison.txt and last_word.txt.
Now comparison.txt has words from the sentence that share consonant letters with the last word of the sentence.
comparison.txt is needed in the percentage calculation later on.
Now intermediate.txt, consonant_words.txt, comparison.txt, and last_word.txt are closed and the while loop is finished.
Now comparison.txt is opened again and the matching words are printed on the screen.
This is not the whole sentence, onlt the last word and words with matching consonants: paraphrase version, to get to the truth of the sentence.
Now comparison.txt is closed.
Now last_word.txt is opened again, the last word is put into the sentence “The last word is:”.
Now last_word.txt is closed.
Now comparison.txt is opened again, and the word is put as a variable, along with the variable ‘message’ in the percentage_calculation function.
void percentage_calculation(char *a_pch, char *message)
Now the sentence from comparison.txt is broken down into a word per line, and each word is individually put into a while loop.
The whole loop places the word into one of four categories, with ‘B’ being consonant and ‘A’ being vowel: ABA, AB, BA, BAB.
Then all words now given one of these four values the math is done to see how much percentage wise a type of word was used in the sentence.
Then, using if statements I check to see which of the four values was the largest, and the result is passed back into the ‘message’ variable and sent back to the redefined_sentence function.
Also the percentages are printed on the screen.
Now back in the redefined_sentence function, it puts the ‘message’ and ‘last_string’ variable into the word_generator function.
void word_generator(char* C_F_two, char *message)
C_F_two = ‘last_string’ variable.
Using if statements, I check if the C_F_two word has a vowel and letter value, if it does the vowel, letter, ‘C_F_two’ and ‘message’ variables are passed into the search function.
void search(char *src, char *a, char *b, char *c, char *message)
Opens the readfile.txt, which has the dictionary and using a while loop goes through the dictionary a word at a time.
I pass the first character and second last character of the dictionary word into their own variables.
Then, using a for loop I break the dictionary word into individual characters/letters.
Then, in the same calculation: I check if the vowel is one of the letters from the for loop, and if the letter is either the first character or second last character of the dictionary word.
So all these steps are per-qualifiers.
If a word qualified the number value is incremented by one, the value is never reset so the value increases with qualified words.
Then I choose qualified words based on their number and save them to a variable to be displayed later.
How the number qualifies the word is like ducks flying through the air during migration, the leader is neither the first or last word, so I wait for a few results then pick one.
Yes, I used ducks to model my code, don’t laugh, I got the idea after watching a mythbusters episode on the tv.
Then I print the four results to screen, and using the ‘message’ variable I compare it to see the value of message and print the result in the sentence:
“printf(“The result using Analysis part ones data is: %s\n”, d_d);”, where d_d is one of the qualified words.
The I close the program. So a lot of steps but they aren’t rocket science steps, I think. The code was made by a novice C programmer, me, so it’s not ultra advanced sci-fi code.
Here is a short version of the description:
int split_by_sentence(void) takes articles and breaks them down into a sentence per line so articles can be fed into the program.
void redefined_sentence (char* sentence) created a hidden sentence from a sentence that reveals the hidden truth the writer is thinking as he writes,
then uses this to make a percentage which is then fed into the search function to print the matching qualified word.
void word_generator(char* C_F_two, char *message) ID’s the vowel, letter combination of the word and goes to search function.
void search(char *src, char *a, char *b, char *c, char *message) qualifies words, then picks the word after x number to make sure it is not the first or last result.
And using the word from percentage function prints that below the four matching words.
I wrote this because I thought you might be confused if you only read the code without me telling you what happened.
There’s only 1931 lines.
I wish I knew enough C to make it smaller, but I don’t.