in c how would you write the code to open a file called myfile.dat and return whether the file is empty or not
in c how would you write the code to open a file called myfile.dat and return whether the file is empty or not
What will fwrite do in regards to finding the file size? Do you mean fstat?
first you will have to declare a pointer of type FILE.
then you will have to open the file using the fopen("PATH_to_file","access mode") function which returns a FILE struct, which can be assigned to the pointer.
if i remember correctly, the pointer now points to a char pointer in the struct returned. the char pointer in turn points to the first character in the opened file.
Now once you can access the first character of the file, now you can check what you want.
This is where i learned this stuff:
C File I/O Tutorial - Cprogramming.com
> the char pointer in turn points to the first character in the opened file.
Wrong. Pointers cannot point to places on a hard drive. There is no char pointer, only the FILE struct, which can then be passed to functions that will perform actions upon the file.
Also, having the first character of a file isn't necessary to determine the size.
ok sorry for the wrong info.