Click to See Complete Forum and Search --> : Why this is an endless loop?
abdul
Aug 14th, 2001, 09:56 PM
Simple:
I want to get the size of a file but the following code loops forever and freezes my application:
FILE *file;
int filesize;
while(!feof(file))
{
filesize++;
}
What is wrong with this code and why does it freeze?
Zaei
Aug 14th, 2001, 11:26 PM
Because you arent doing anything to the file. You are basically doing this:
for(INT fileSize = 0; ; ++fileSize);
There is no condition to end the loop, because you arent seeking the file.
Z.
abdul
Aug 14th, 2001, 11:41 PM
So how can I get the file size using C functions - not API
kedaman
Aug 15th, 2001, 12:37 AM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt__filelength.2c_._filelengthi64.asp
Zaei
Aug 15th, 2001, 12:38 AM
Very likely, there is a function that will retrieve a files attributes. Look around in the MSDN.
Z.
Zaei
Aug 15th, 2001, 12:38 AM
Grrrr... =).
Z.
kedaman
Aug 15th, 2001, 12:45 AM
heheh :p
abdul
Aug 15th, 2001, 01:12 AM
How come MSDN has the resource for general C\C++ programming language
HarryW
Aug 15th, 2001, 06:59 AM
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().
parksie
Aug 15th, 2001, 07:54 AM
You can also use _stat to get the file's information. Search for stat.c and that will give an example :)
abdul
Aug 15th, 2001, 09:47 AM
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().
Sorry, I just wrote the code in post. I had already opened the file using "fopen" command;)
MPrestonf12
Aug 15th, 2001, 06:32 PM
try something like GetFileAttributes{API though}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.