title: How to read file index of a directory using C/C++?
body: <p>What method (or a library function) do we use in C or C++ to read the file index ( i.e., the list of all the files) in a directory.</p>
  
  <p>My motive is to create a function to make an extended search possible in a directory (or a file system) by reading the list of files in a directory. Since we don't already know what files are existing on the disk we cannot open and read them.</p>
  
  <p>However, I know that programs like 'ls' and 'dir' in Unix/Linux are able to read the contents of a directory; since these OS are also written mostly in C, there must be some way to create a similar function under one program.</p>
  
  <p>Following is the algorithm that I want to use:</p>
  
  <ol>
  <li>Take input from the user to navigate to a directory on the file system</li>
  <li>Read the contents of the file</li>
  <li>Make a linked list and add to it the contents of the directory that we just read</li>
  <li>Use the linked list to read the file name and one by one search through file contents using an existing algorithm</li>
  <li>Writing the output to the screen explaining the results found (results are indexed in an order or priority decided by an existing algorithm).</li>
  </ol>
  
  <p>I have coded the algorithms used in step 4 and 5, and can do the step 1 and 3 on my own. The only problem that I'm having is with step 2. Is there any librairy in C/C++ or any other method by which we can achive the solution to this problem?</p>
  
  <p>Thank you!</p>