Organise the Gregorian Church's Music
C, 171 146
i,b;main(int c,char**v){for(;c=v[1][i];)b|=c/65&lt;&lt;c*2%7+v[1][++i]%2*7;for(i=12;i--;)b&amp;(1016056&gt;&gt;i)||printf(&quot;Dorian scale in %c%c&quot;,65+i*3%7,(i&lt;5)*35);}

Parsing strings in C is not that easy, so I went for a more mathematical approach.
I take advantage of the Circle of Fifths. If we arrange the notes in the following order based on counting up 7 semitones at a time (known as a &quot;fifth&quot;), we find that all the notes permitted in any given scale form a consecutive block of 7 notes and all the prohibited notes form a consecutive block of 5 notes.
F C G D A E B F# C# G# D# A#

(it's a circle, it wraps back around to F at the end.)
The position of a natural note in the above sequence can be calculated as (ASCII code) * 2 % 7. Then if the next character is odd (applies to # but not comma, space or zero byte) we add 7 to make it sharp. We store a bitmap of the notes that have been used.
The number 243 (binary 11111000) corresponds to the notes prohibited in the scale of A# Dorian. I multiplied this by (1&lt;&lt;12)+1=4097 to give the magic number 1016056. This is rightshifted to check (by ANDing) if the melody contains prohibited notes for each of the 12 scales in turn. If the melody does not contain prohibited notes, the scale is printed.
For the output we need to print the scale name encoded in the reverse order to cycle of fifths above, remember we are going backwards because we are rightshifting.) The ASCII sequence ADGCFBEADGCF is generated by 65+i*3%7. For the first five of these a sharp must also be printed.
Ungolfed code
i,b;
main(int c,char**v){
  for(;c=v[1][i];)                          //for each character in first commanline argument v[1]
                                               //if it is a letter (assume uppercase, ASCII 65 or over)
   b|=c/65&lt;&lt;c*2%7+v[1][++i]%2*7;               //convert to position in the circle of fifths. 
                                               //Add 7 if the next character is odd (ASCII'#')
                                               //leftshift 1 by this number and OR this with the contents of b.

  for(i=12;i--;)b&amp;(1016056&gt;&gt;i)||printf         //if melody includes no prohibited notes for the scale i, print
   (&quot;Dorian scale in %c%c&quot;,65+i*3%7,(i&lt;5)*35); //the scale letter, and a # (ASCII 35) if required, otherwise an ASCII 0.
}

Invalid input behaviour: If insufficient notes are supplied to unambiguously determine the scale, it will output all possible scales. If an impossible combination of notes is supplied, it will output nothing. Notes must be delimited by a comma (or other non-whitespace character with an even ASCII code &lt;= 64.) Spaces cannot be used as everything after the first space would be considered a different argument. ASCII codes &gt;64 will be interpreted as notes in the manner described.