![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with socket reading | swap007 | UNIX for Advanced & Expert Users | 2 | 05-20-2008 10:08 PM |
| help me ...problem in reading a file | brkavi_in | Shell Programming and Scripting | 6 | 06-19-2006 09:41 AM |
| Reading file names from a file and executing the relative file from shell script | anushilrai | Shell Programming and Scripting | 4 | 03-10-2006 02:25 AM |
| Reading a CSV file into shell variables problem | multidogzoomom | Shell Programming and Scripting | 6 | 10-11-2005 01:43 PM |
| Using fread if the buffer size is not known | jlrodz | High Level Programming | 1 | 10-23-2002 06:59 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi All,
These are the two ways i tried to read file but i getting work with second one not with the first. char buf[2000]; // Defining space for buf ctrlfnum = fopen(filename_arr.control_fname,"r"); 1) n = fread(buf,sizeof(buf),1,ctrlfnum); ============== (not works) 2) n = fread(buf,1000,1,ctrlfnum); ================== (Works) NOTE : i'm using HP-UX C++. Awaiting reply. Thanks in advance. Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
sizeof(a pointer to something) = size of a pointer variable, = 4 on a 32 bit machine.
sizeof(buf) is likely 4, not 1000. |
|
#3
|
|||
|
|||
|
Thanks man,, I got what are yoy saying ...Thanks a lot ..
Can you please suggest can i make it works by fread . Thanks in advance , Arun Kumar |
|
#4
|
|||
|
|||
|
You need to have a way to know the maximum size of buf.
Try something global like a define. Code:
#define REC_SZ 1000
......
int foo()
{
char buf[REC_SZ]={0x0};
bar(buf);
}
char *bar(char *buf)
{
.............
fread(buf,REC_SZ,1,ctrlfnum);
return *buf;
}
|
|
#5
|
|||
|
|||
|
Quote:
sizeof(buf) => 4 char buf[2000]; sizeof(buf) => 2000 Regards |
|||
| Google The UNIX and Linux Forums |