The problem is that if the data returned by your getline function is less than the length of
, you will get an error. For example, if the line it reads is empty, you will immediately get a problem.
Try it: put a breakpoint on the getline, and see what it returns each time. Then add a check to ensure there are at least as many characters as you are going to compare against before you enter the loop!