title: C open a file for reading in a diferrent directory
body: <p>Got a doubt about file system manipulation: opening a file in a different directory where we execute our program. </p>
  
  <p>Lets say we execute our program in the following directory: /home/example and we want the program to go to another directory, say: home/example/Inside/Test and open all the txt files in this last directory. </p>
  
  <p>Ok so a small code:</p>
  
  <pre><code>  /*variables*/
    struct dirent *strdir;
    DIR *diro; 
    struct stat statbuffer;
    char *path = /home/example/Inside/test
  
    diro = opendir( path )
    /*cheked it opened properly*/
    while ( (strdir = readdir(diro)) != NULL ){
       stat(strdir-&gt;d_name, &amp;statbuffer);         /*Gets information of file*/
       if (S_ISREG(statbuffer.st_mode)){
         /*its regular type*/
         /*check its of type txt*/
         ???
  </code></pre>
  
  <p>I put <code>???</code> because I used fopen, and it doesn't work. Of course it doesn't, because that file does not exist in /home/example. Same goes for open.</p>
  
  <p>So I thougth, maybe I can concatenate the directory and the file name into a single char to get the full path, but that sounds kind of ugly...</p>
  
  <p>The other idea is to use the information given to me by stat, but I can't seem to figure out how to make it work. Hard links?</p>