The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 03-10-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
Quote:
The below one is what I coded in my program: read(fd,name,sizeof(name));
Was mine a right one?
sizeof(name) is 20 since you defined name as an array of 20 characters i.e. char name[20]. Therefore your program tries to read 20 bytes at a time - with no error checking.

Quote:
while (read(fd, (void *) name, (size_t) 5) == 5)
Here the program tries to read 5 bytes and checks that it has actally read 5 bytes. size_t is defined by ISO C for use in representing size information and is very useful whien code portability across different architectures and programming models is desirable. It is required to be an unsigned integral type. Typically it is an int or long.