title: can't open file, file descriptor returns -1 value
body: <p>When I run this program. The file descriptor returns <code>-1</code> value and hence the program terminates. I don't know why is this happening. As the pid value is exactly the name of the file that I want to open.</p>
  
  <pre><code>const char *psyn = "product/productId:";
  char line[100];
  pFile = fopen ("pids.txt" , "r");
   if (pFile == NULL) perror ("Error opening file");
  else {
      while(fgets (line , sizeof(line) , pFile))
          {
          if (strstr(line, psyn) == line)
              {
              leng = strlen(line);
                      if( line[leng-1] == '\n' )
                          line[leng-1] = 0;
                      if( line[0] == '\n' )
                          line[0] = 0;
              pid = line+strlen(psyn)+1;
                              strcat(pid,t);
  
              leng = strlen(pid);
                      if( pid[leng-1] == '\n' )
                          pid[leng-1] = 0;
  
              fd = open(pid, O_RDWR, 0644);
                if (fd == -1)
                                 cout&lt;&lt;"eror in file \n";
                 else { //.. rest of the program}
  </code></pre>