This code is from a book and is supposed to open & display the contents of a file ::
This file called H_World.C is located in C:\TCCode:#include<stdio.h> void main() { FILE *fp; char ch; clrscr(); fp=fopen("H_World.c","r"); while(1) { ch=fgetc(fp); if(ch==EOF) break; printf("%c",ch); } fclose(fp); getch(); }
My first question is that how does the compiler know that it has to search in C:\TC??
Now I tried to experiment something.........
**1.)I made a readme.txt file in C:\TC and in the fopen argument wrote "C:\\TC\\readme.txt"
It worked !!
**2.)Now i made a folder called NEW in C:\ and put this readme file in the NEW folder,made the argument "C:\\NEW\\readme.txt".This also worked!
**3.)I put the readme file in F:\ drive....this also worked.
**4.)Now i created a new folder in F drive ,put the file in new folder,made the necessary changes in the code but it returned a "Null Pointer Assignment"
Please explain me how does this fopen() works,where does it search for the files(The book i read says it searches for the file on the entire Hard Drive but i dont think so)and why does it give error messege in experiment no.4?
Thanks...........