Instead of the non-informative
Code:
printf("Cannot open %s.\n",fname);
try using perror instead. It should tell you why the file can't be opened. Chances are that the program is looking in a different location that where the file is.
>void main(void)
void main is only valid if you're on a freestanding implementation. Since you're learning C, this is highly unlikely. Use one of these:
Code:
int main(void) /* No arguments */
int main(int argc, char **argv) /* Command line arguments */
And of course, return an integer value at the end.