Thursday 15 May 2014

c - opening descriptor and closing , why does it matter? -


I have the following code that prints on the screen: haha ​​in the file:

  Haha Hello father finished   

If I delete line 6 and 7, why do I get different results?

  int main () {// creates a new file containing full read / write int fd = open ("myfile", O_RDWR | O_CREAT, 0666); Write (FD, "Haha \ n", 5); Close (FD); // line 6 fd = open ("mimefile", o_rrdwr); // line 7 off (0); Pass (1); Dup (FD); Dup (FD); If (fork () == 0) {char s [100]; Dup (FD); Scanf ("% s", s); Printf ("hello \ n"); Write (2, s, strollon (s)); Return 0; } Wait (faucet); Printf ("Dad ended \ n"); Close (FD); Return 0; }    

scanf (), try compiling again and commenting again ScanF () may be trying to read beyond the EOF that something happening in the internal library of the stdio library, which is causing the problem in the printf () buffer, the process is not being slipped from time to time Just a guess ...

No comments:

Post a Comment