Hi there,
Quote:
Originally Posted by postiwala
Code:
char buf [1000];
int len = 500;
FILE* fp = fopen(filename,"rb");
remove(filename);
size_t nread = fread(buf,1,len,fp));
Will the code work?
|
yes and no, depending on what you expect. Well, I didn't try, but in theory, the OS should refuse to delete an open file, and so remove() should fail. But you don't even check for that error condition, you ignore the result of remove().
Quote:
Originally Posted by postiwala
Will fread be able to read the data?
|
Yes. At the time you tried to delete the file, it was open. So the delete action was refused, and the file remains intact.
Quote:
Originally Posted by postiwala
On my system, I can see that sometimes fread returns 0 and sometimes it returns 500.
|
That's interesting. As I said: In theory, ...
And you know: Only in theory, theory and practise are exactly the same. ;-)
[X] Doc CPU