Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have some file to read and i need to know how can i get data from my file byte by byte.

What I have tried:

 for(j = 0; j < 140; j = j + 7)
{
   u16BytesRead = fread(&u8Buffer, 1, 7, fp); // what is the value of u16BytesRead  here ??

   }
Posted
Updated 16-Apr-18 5:04am

If you want to read it byte by byte, then change the 7 to a 1:
u16BytesRead = fread(&u8Buffer, 1, 1, fp);


If you mean "what does fread return?" then look at the documentation: fread - C++ Reference[^] which clearly says:
Quote:
Return Value
The total number of elements successfully read is returned.
If this number differs from the count parameter, either a reading error occurred or the end-of-file was reached while reading. In both cases, the proper indicator is set, which can be checked with ferror and feof, respectively.
If either size or count is zero, the function returns zero and both the stream state and the content pointed by ptr remain unchanged.
size_t is an unsigned integral type.


But just calling fread in a loop won't help you - you will just overwrite the data you read lats time each time you call it.

Perhaps if you explain what you are trying to do in better detail, we may be able to help you more, but at the moment that is all we can do.
 
Share this answer
 
Comments
BaselAla 17-Apr-18 1:23am    
thank you
OriginalGriff 17-Apr-18 2:56am    
You're welcome!
Quote:
i need to know how can i get data from my file byte by byte.
what is the value of u16BytesRead here ??

When you basically want to understand how a standard function works, reading the documentation is the first place to go.
fread - C++ Reference[^]
fread - cppreference.com[^]
C library function fread()[^]
Documentation is available on internet and is much more complete than any of our answers and faster than us.

Then if you are not sure, experimentation is the best way to know what is what.
Using the debugger also allow you to see what is going on in your code as it execute.
 
Share this answer
 
Comments
BaselAla 17-Apr-18 1:23am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900