The explanation for my program:
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.
Besides corgi.c, you need these text files:
readfile.txt needs the diction from sourceforges 'kevins word list'.
I use the Official 12Dicts Package, I copy and paste the contents of '2 of 12.txt' into readfile.txt.
Here are some example sentences i put into the program:
To open walrus.c, remove the txt extension, then unzip it.Code:Input a sentence. Press Enter when done. To some degree, the current Nintendo Wii console already features an "app store" called the Wii Shop Channel. Console owners can browse, purchase, and download bite-sized games called WiiWare in addition to old classics (ROMS) from the Supe r Nintendo, Sega Genesis and TurboGrafix 16 days. the current Nintendo console already an called the Shop Channel The last word is: Channel _______________________________________________________________ Analysis part one: __________________ letter vowel letter 0.300000 letter vowel vowel 0.500000 vowel vowel letter 0.100000 vowel vowel vowel 0.100000 Analysis part two: __________________ Using the last word of the sentence: Channel, these are four possible word associations: half-dollar haggle dilettantish commonwealth The result using Analysis part ones data is: half-dollar _______________________________________________________________ Console owners browse purchase and download bitesized games called addition old classics Nintendo Genesis and days The last word is: days _______________________________________________________________ Analysis part one: __________________ letter vowel letter 0.500000 letter vowel vowel 0.187500 vowel vowel letter 0.250000 vowel vowel vowel 0.062500 Analysis part two: __________________ Using the last word of the sentence: days, these are four possible word associations: bachelorhood annoyed adulthood add The result using Analysis part ones data is: adulthood _______________________________________________________________ Press any key to continue . . .
Thanks to everyone who helped me. I started this in late October early November and have been at it everyday since, now it's done.
I know 1931 lines is a lot but most is copy and paste that Salem warned me about, but those copy and paste I forget how to make smaller code. But it works and that's what matters to me.