The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-27-2006
Registered User
 

Join Date: Oct 2004
Posts: 235
Thumbs up problem in reading file using fread

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
Reply With Quote
Forum Sponsor
  #2  
Old 10-28-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,269
sizeof(a pointer to something) = size of a pointer variable, = 4 on a 32 bit machine.
sizeof(buf) is likely 4, not 1000.
Reply With Quote
  #3  
Old 10-30-2006
Registered User
 

Join Date: Oct 2004
Posts: 235
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
Reply With Quote
  #4  
Old 10-30-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,269
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;
}
Reply With Quote
  #5  
Old 10-30-2006
Registered User
 

Join Date: Feb 2005
Posts: 53
Quote:
Originally Posted by jim mcnamara
sizeof(a pointer to something) = size of a pointer variable, = 4 on a 32 bit machine.
sizeof(buf) is likely 4, not 1000.
char *buf;
sizeof(buf) => 4

char buf[2000];
sizeof(buf) => 2000

Regards
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0