You said the code isn't designed to work, were you referring to the code i originally posted? Or to sundips code?
Sundips. Didn't you bother reading my post between his code and your attempt? I explained exactly what was wrong with his code.
The maximize size the file can be is 60kb. And no more than 20 lines.
To test the 1st character, read the first line. Test for and ignore all initial SPACES. If the first non-SPACE is a digit, you're OK, otherwise a bad file.
To test the last character, read the rest of the file. When you get to EOF, test the last characters in your buffer for whitespace (which includes the \n) which you skip. The first non-whitespace character also needs to be a digit, otherwise the file is bad.