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.