Simple:
I want to get the size of a file but the following code loops forever and freezes my application:
Code:FILE *file;
int filesize;
while(!feof(file))
{
filesize++;
}
What is wrong with this code and why does it freeze?
Printable View
Simple:
I want to get the size of a file but the following code loops forever and freezes my application:
Code:FILE *file;
int filesize;
while(!feof(file))
{
filesize++;
}
What is wrong with this code and why does it freeze?
Because you arent doing anything to the file. You are basically doing this:
There is no condition to end the loop, because you arent seeking the file.Code:for(INT fileSize = 0; ; ++fileSize);
Z.
So how can I get the file size using C functions - not API
Very likely, there is a function that will retrieve a files attributes. Look around in the MSDN.
Z.
Grrrr... =).
Z.
heheh :p
How come MSDN has the resource for general C\C++ programming language
It doesn't have the resource, it's just a resource available. It just happens to be a very useful resource though, especially if you're using Windows.
You'll need to actually open a file before you can get its attributes, currently you're just declaring a pointer to a file. The standard C way to do that is using fopen().
You can also use _stat to get the file's information. Search for stat.c and that will give an example :)
Sorry, I just wrote the code in post. I had already opened the file using "fopen" command;)Quote:
Originally posted by HarryW
You'll need to actually open a file before you can get its attributes, currently you're just declaring a pointer to a file. The standard C way to do that is using fopen().
try something like GetFileAttributes{API though}