473,396 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to use the fread() function???

Pls help me..... I need to read 131067 items with a size of 1 byte each item...
if(fread((void *) pBuffer,1,512*256,pGList)==0)
{
cout<<"Cannot read file";
return -1;
}
is this code correct?????
Aug 18 '06 #1
3 5359
Banfa
9,065 Expert Mod 8TB
Well 512 * 256 = 131072 not 131067 so the size is wrong

and since you have not told us how pBuffer and pGList are declared it is impossible to tell.
Aug 18 '06 #2
sorry if i lack the declaration of the pBuffer and pGList...
by d way this is hw i declare it....

unsigned char huge *pBuffer;
file *pGLIst;
if((pGList= fopen("glist.bin", "rb"))==NULL)
cout<<"Error opening file";
pBuffer=(unsigned char huge *) farcalloc(0x20000,1);
if(pBuffer==NULL)
cout<<"Insuficient Memory";
if(fread((void *) pBuffer,1,512*256,pGList)==0)
cout<<"Cannot read file";
return -1;
}
Aug 22 '06 #3
Banfa
9,065 Expert Mod 8TB
looks more or less right, if pBuffer is NULL then you still try to use it which will fail nastily
Aug 26 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: rendl42 | last post by:
Hey all, I'm a relative newbie to PHP, and am getting some strange results with the fread() function with PHP (win32) 5.1.2. Here is some code: <?php echo $_SERVER."<br>"; echo $_SERVER;...
4
by: janssenssimon | last post by:
//de structure om de highscores in op de slagen typedef struct score{ char *naam; int veld; int score; struct score *volg; }HIGH; void toonhighscores(void)
8
by: M. Åhman | last post by:
I'm reading "C: A Reference Manual" but still can't understand a very basic thing: is there any functional difference between fgetc/fputc and fread/fwrite (when reading/writing one unsigned char)?...
3
by: cinsky | last post by:
Hi, While reading ISO C Standard, I found follow text in 7.19.8.1: size_t fread(void *restrict ptr, size_t SIZE, ...) ... For each object, SIZE calls are made to the fgetc function and the...
13
by: 010 010 | last post by:
I found this very odd and maybe someone can explain it to me. I was using fread to scan through a binary file and pull bytes out. In the middle of a while loop, for no reason that i could...
5
by: David Mathog | last post by:
When reading a binary input stream with fread() one can read N bytes in two ways : count=fread(buffer,1,N,fin); /* N bytes at a time */ or count=fread(buffer,N,1,fin); /* 1 buffer at a...
20
by: ericunfuk | last post by:
If fseek() always clears EOF, is there a way for me to fread() from an offset of a file and still be able to detect EOF?i.e. withouting using fseek(). I also need to seek to an offset in the file...
3
by: venkat | last post by:
Hi, I am learing Unix internals. I have come across a problem where i am not able to understand what is happening. As i gone through the book i found that lseek will give the physical descriptor...
6
by: ryanselk | last post by:
Hey all, I have a c function im putting into c++ (dont ask why, tell you the truth, I really dont know!). I am having a bit of problem deciding on how to use a new method of fread. Here is the...
15
by: =?ISO-8859-15?Q?L=E9na=EFc?= Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all, For some reasons, somewhere in a program, I'd like, if possible, to quickly parse a whole file before rewinding it and letting the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.