|
-
Aug 14th, 2001, 09:56 PM
#1
Thread Starter
PowerPoster
Why this is an endless loop?
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?
-
Aug 14th, 2001, 11:26 PM
#2
Because you arent doing anything to the file. You are basically doing this:
Code:
for(INT fileSize = 0; ; ++fileSize);
There is no condition to end the loop, because you arent seeking the file.
Z.
-
Aug 14th, 2001, 11:41 PM
#3
Thread Starter
PowerPoster
So how can I get the file size using C functions - not API
-
Aug 15th, 2001, 12:37 AM
#4
transcendental analytic
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 15th, 2001, 12:38 AM
#5
Very likely, there is a function that will retrieve a files attributes. Look around in the MSDN.
Z.
-
Aug 15th, 2001, 12:38 AM
#6
-
Aug 15th, 2001, 12:45 AM
#7
transcendental analytic
heheh
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 15th, 2001, 01:12 AM
#8
Thread Starter
PowerPoster
How come MSDN has the resource for general C\C++ programming language
-
Aug 15th, 2001, 06:59 AM
#9
Frenzied Member
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().
Harry.
"From one thing, know ten thousand things."
-
Aug 15th, 2001, 07:54 AM
#10
Monday Morning Lunatic
You can also use _stat to get the file's information. Search for stat.c and that will give an example
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 15th, 2001, 09:47 AM
#11
Thread Starter
PowerPoster
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
-
Aug 15th, 2001, 06:32 PM
#12
Hyperactive Member
try something like GetFileAttributes{API though}
Matt 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|