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
read and write from a file rinku Shell Programming and Scripting 2 01-10-2008 09:22 PM
Problem with read & write EltonSky High Level Programming 11 08-31-2006 11:35 AM
sed to read and write to very same file 435 Gavea Shell Programming and Scripting 5 06-29-2006 08:04 PM
How to implement read/write thread shilpi_gup High Level Programming 1 10-23-2005 11:35 PM
popening for read and write szzz High Level Programming 1 11-18-2003 08:05 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-12-2002
Registered User
 

Join Date: Jul 2002
Location: Italy - Naples
Posts: 6
Stumble this Post!
Question read, write & STDOUT_FILENO....

hi guys, I'have a question 4 u.

Why this code give me the right output (an integer on the stdout):

Code:
read(fd,&mpid,sizeof(pid_t));
printf("%d\n",mpid);
Instead this code give me only a blank line:

Code:
read(fd,&mpid,sizeof(pid_t));
write(STDOUT_FILENO,&mpid,sizeof(pid_t));
?????

The "fd" file descriptor points to a fifo, but I think this isn't important cause I've got the same problem if i try reading from a normal file.
__________________
M3xican
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-12-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,430
Stumble this Post!
mpid is an integer, but when you send it though printf with the format you are using, it gets converted into a string of ascii characters. This string can be be displayed. In the second case you are sending the integer directly to stdout. If integers are 32 bits on your system once in a while it may be 3 printable characters followed by a null byte and thus look like a string. But most of the time it will be unprintable.
Reply With Quote
  #3 (permalink)  
Old 07-17-2002
Registered User
 

Join Date: Jul 2002
Location: Italy - Naples
Posts: 6
Stumble this Post!
Thanx

Thanx a lot Perderabo.
__________________
M3xican
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:34 PM.


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

Content Relevant URLs by vBSEO 3.2.0