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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:25:28+00:00 2026-06-08T13:25:28+00:00

The _findnext() function is not working when called for the second time. Here is

  • 0

The _findnext() function is not working when called for the second time. Here is the code.

int main() {
    struct _finddata_t ffblk;
    intptr_t done;

    chdir("tmp");
    printf("Directory changed to dir successfully\n");

    done=_findfirst("*.txt",&ffblk);
    printf("Call to findfirst successful\n");
    printf("%s\n",ffblk.name);
    do{
        done=_findnext(done,&ffblk);
        printf("%s\n",ffblk.name);
    } while(!done);
    printf("Exited the main loop\n");
    getch();
}

The program crashes once it gets and prints the name of first two files in the folder tmp.
The first file name printed is from the findfirst() function. The next file name is printed by findnext(). I have checked via debugging.

Now when findnext() is called the second time in the loop, the program crashes. I am using gcc and tried most of the things with return value too, but no success. Any ideas ?

  • 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-08T13:25:29+00:00Added an answer on June 8, 2026 at 1:25 pm

    Your problem is that you cannot assign the value of _findnext to your handle, you need two variables:

    intptr_t handle = 0;
    int done = 0;
    
    handle = _findfirst("*.txt",&ffblk);
    while(handle && done != -1)
    {
        printf("%s\n",ffblk.name);
        done = _findnext(handle,&ffblk);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code File external.js: var TRange=null; function findString (str) { if (parseInt(navigator.appVersion)<4)
the following code lists files but not directories var rec : tsearchrec; begin findfirst('c:\test\*',faanyfile-fadirectory,rec);
Here's the current code I have got private void recalculateRRange(Excel.Range UsedRange) { Excel.Range currentRRange
Is FindFirst,FindNext & FindClose Thread safe in delphi ? If not what should be
I have used the Find_Range function from OzGrid which returns a Range object with
I am trying to make a find, find next function for my program, which
I'm encountering a big problem when i'm trying to make a recursive search function
Ive been making a find, find next function for my richtextbox, so I have
I'm trying to convert some code from Python to C++ in an effort to
I'm working on adapting a jQuery slider that originally had 10 thumbnails. I only

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.