First issue would be deciding what the root note is, otherwise as kurto says you'll get several answers for one set of note letters.
Would the order of the letters matter? Maybe you could adopt a rule that the first letter is always the root ?
Assuming you tackle that somehow (or just accept several answers), you could ...
Assign a number to each letter (presumably you're accepting sharps and flats too?) and use that to calculate the interval between the notes, in semitones eg what we calla 4th = from A to D is actually 5 semitones.
You could then use the intervals to match a set of known chord patterns against the root note:
C E G as in your example, in semitones = 0-4-7 = [rootnote] major = the relative pattern for a major triad.
C Eb G = 0-3-7 = pattern for minor chord.
0-4-7-10 = Cmaj 7
Each time you're just reporting the root note with a comment about how the rest of the notes are arranged. The limitation would be where a chord is percieved but the root note is missing - but that could be interpreted as some other chord anyway.
The more pattern templates you identify, the better it'll become but you only need to define them relative to a root note in semitone numbers.
If somenthing fits noneof the patterns (perhaps you haven't set one up for chord A4) then you just write the return the root note with extra note number (not semitone number).
So you need
- a way to convert all letters (sharps and flats) to numbers = a lookup table / associative array
- a way to identify the root note
- a way to identify the intervals of all letters from the root note = turn into numbers and subtract the root note number. Modulus by 12 to keep it within 1 octave (or not if you want to get more advanced and handle negative intervals, for notes beneath the root note)
- a way to define pattern templates for known chords, with name text associated
- a way to compare semitone numbers to patterns (= an array comparison)
- a way to turn semitone intervals into note numbers (eg 5 semitones = 4th note on scale) so that you can return things like A4
If you wanted to return all possibilities for a set of notes then you could return the result for your routine, using each note in the chord as the root, in turn.
I'm thinking on my feet here but I think that's how I'd go about it.