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 7066275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:03:48+00:00 2026-05-28T05:03:48+00:00

Essentially, what I’m trying to do is to check the last access time of

  • 0

Essentially, what I’m trying to do is to check the last access time of a file and compare it with a string. Here’s the relevant block:

struct stat file;
char timeStr[ 100 ];

stat(nodes.at(0), &file);
strftime(timeStr, 100, "%H:%M:%S-%m/%d/%y", localtime(&file.st_atime)); /* problem */

nodes is a vector of file paths; I’m not sure if it’s relevant but I’ll include the code that I’m using to set nodes:

vector<char*> nodes;
DIR *dir;
struct dirent *cur

if((dir = opendir(searchPath.c_str())) == NULL) {
    cout << "Error opening search path. Are you sure '" 
        << searchPath.c_str() << "' is a valid search path?" << endl;
    return 0;
}
while((cur = readdir(dir)) != NULL) {
    if(string(cur->d_name) == "." || string(cur->d_name) == "..") continue;
    nodes.push_back(cur->d_name);
}
closedir(dir);

Where searchPath is a user-inputted string.

The problem: when the ‘problem’ line is run, from there on nodes is a vector of garbage. I’m wondering if I can accomplish this task without turning nodes into garbage.

Since this is homework, and as you can probably tell I’m not used to C++, a solid push in the right direction will be given the ‘accept’.

Thank you.

  • 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-05-28T05:03:49+00:00Added an answer on May 28, 2026 at 5:03 am

    It has nothing to do with your strftime call but with the fact that (from here):

    The pointer returned by readdir() points to data which may be overwritten by another call to readdir() on the same directory stream.

    Since you’re simply pushing a character pointer that points to data that may be overwritten by subsequent calls to readdir, you may well end up with garbage.

    You can probably fix it by using a copy of the C string with something like:

    nodes.push_back (strdup (cur->d_name)); // plus error handling if need be.
    

    And, if your implementation doesn’t have a strdup (it’s not part of the standard), you can use mine (found here).

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

Sidebar

Related Questions

Essentially, I'm trying to achieve the affect of text-align:justify but with floating block elements.
Essentially I have 3 fields I want to check for: class Book { String
Essentially, I need to parse the response string of the CHAT CREATE command with
Essentially, I want to check another object to see if an attribute is set
Essentially here I want the modal form sheet to be transparent so I can
Essentially what I want is for the app, once the user has allowed access
Essentially Im trying to get many many java clients connect to a socket on
Essentially I'm trying to combine the two resource declarations into one command. resource :documents,
Essentially I'm trying to create the HTML/CSS for an auto-complete. I want it to
Essentially the title of this question explains the essense of what I am trying

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.