Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8896077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:57:09+00:00 2026-06-14T23:57:09+00:00

What is the correct way to read and extract data from text files when

  • 0

What is the correct way to read and extract data from text files when you know that there will be many in a directory? I know that you can use fopen() to get the pointer to the file, and then do something like while(fgets(..) != null){} to read from the entire file, but then how could I read from another file? I want to loop through every file in the directory.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:57:10+00:00Added an answer on June 14, 2026 at 11:57 pm

    Sam, you can use opendir/readdir as in the following little function.

    #include <stdio.h>
    #include <dirent.h>
    
    static void scan_dir(const char *dir)
    {
        struct dirent * entry;
        DIR *d = opendir( dir );
    
        if (d == 0) {
            perror("opendir");
            return;
        }
    
        while ((entry = readdir(d)) != 0) {
            printf("%s\n", entry->d_name);
            //read your file here
        }
        closedir(d);
    }
    
    
    int main(int argc, char ** argv)
    {
        scan_dir(argv[1]);
        return 0;
    }
    

    This just opens a directory named on the command line and prints the names of all files it contains. But instead of printing the names, you can process the files as you like…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the correct way to read Unicode files line by line in C++?
I need to know if this is the correct way (not losing written data
Is there a correct way to read the arguments to a python application? Example:
I want to read from an java.io.InputStream with a timeout. Apparently the correct way
I am wondering what is the correct way to read values from a html
I read the PHP Variable page and it states the correct way to assign
What would be the correct way to create a fully URL-encoded file:// URI from
I have a stream of bytes that is being read in from a socket
I've read many different things about correct memory management for cocoa/objective-c For instance ive
What is the correct way to do this? MySqlDataReader reader = command.ExecuteReader(); while (reader.Read())

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.