Sunday, July 26, 2009

C code - acting weirdly - File operations - fread() failing?

Hi


This code i wrote is for writing some data to a file and then later read that data when required.





The problem is that it works perfectly fine when i tested it in VC++ , But as i wanted it to work with linux i moved this code to linux... there everything is fine but i can't read the data using fread() function !!!





No problem with file as i can read the data using read() and fgetc() functions...





one more thing is that fread_unlocked() function works fine but not fread()





What could be the reason for fread() to fail...





fread() is always returning 2 !!!

C code - acting weirdly - File operations - fread() failing?
The unlock working potentially means that another process is using the file. Close all apps that may be using the data -- including any wordproc window that you may be using to view it. Hopefully that works.
Reply:hi,


check the fread() again.


size_t fread(


void *buffer,


size_t size,


size_t count,


FILE *stream


);


Parameters are:


buffer :Storage location for data.


size : Item size in bytes.


count :Maximum number of items to be read.


stream: Pointer to FILE structure.


No comments:

Post a Comment