>>1
Use a dictionary (i.e. key-value pairs) to hold the frequency table. Have two character variables to hold the previous two characters before the current one.
Then go through all the characters in your ciphertext string in sequence.
For each alphabet character you encounter, add one to its frequency count. If your last character variable contains a value, concatenate that with your current character to form the current bigram, and add one to its frequency count. If your second last character variable contains a value, concatenate that with the last character and the current character to form a trigram, and add one to its frequency count. Then set the second last character to the last character, and the last character to the current character.
If the current character is a space, then clear the last character and second last character variables.
Ignore all other symbols.
To record your frequency counts, take the character or bigram or trigram, and use it as the key for a dictionary lookup. If it exists in the dictionary, read the value, add one to it and write the value back. If it doesn't exist, add it to the dictionary with a value of one.