Code:
while(tok='\n')
should be
Code:
while(tok=='\n')
Also, you never opened an output file, and even if you had, you aren't ever actually outputting the token, you are only outputting the '$'. Your output file would just be:

$$$$$$$$$$$$$$$$$$$$$$$$

Try fixing those problems first and then see if you can figure out the rest.