title: C Read from File will always read 0 bytes
body: <p>I got this problem where i want to read from file using read function, but i cant't. 
  My code does that. I have a parent proccess and a child process. The child does an exec command and i have redirected the stdout to a file f. The parent waits the child and after that is reads from the file it's content and stores it to a buffer. Then i'm sending this output to a client through socket,using send, but that's not the problem. The problem is that even though the txt has content inside from the exec command, read function won't read anything and from my testing it always reads 0 bytes.</p>
  
  <pre><code>                 //parent
  
                      if (wait(&amp;status2)== -1){ // Wait for child
                          perror("wait");
                      }
  
                      check_child_exit(status2);
  
                      n = read(f, buffer, MAX_BUFF-1);
                      if (n &lt; 0){
                          error("ERROR reading from File");
                      }    
                      printf("\n%d\n",n);
  
                      n = send(newsockfd,buffer, MAX_BUFF-1,0);
                      if (n &lt; 0){
                          perror("ERROR writing to socket");
                          break;
                      }
  
  
                 //child
                       dup2(f,1);
                       dup2(f,2);
                          .
                          .
                          .
  
                       execvp(words[0],words); // Execute date
                       perror("execvp");
                       exit(EXIT_FAILURE)
  
  </code></pre>
  
  <p>So as you can see these are the 2 processes. I heard from another article that the problem might be on the opening of the file. But im not sure which options to use or not. I even tried to open with open function and fopen function just to try new things.
  Here are the open and fopen call:</p>
  
  <pre><code>        f = open("temp133",O_RDWR|O_CREAT|O_TRUNC,0755);
          if (f==-1){
              error_exit("Error Exit");
  
          }
  
          FILE *fd=fopen("tmp","w+");
  </code></pre>
  
  <p>thanks in advance</p>