See, gets and fgets work differently. The first ignores the newline character while the second adds it to the string. I suggest using fgets for both the console and file input. Like this:
Code:
fgets(a, 30, stdin);