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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:51:43+00:00 2026-06-05T21:51:43+00:00

While traversing from my current path , and searching for a file , I’m

  • 0

While traversing from my current path , and searching for a file , I’m having problems locating the file .

I suspect the that the path is the blame for that due to chdir , in the next code :

The associated folders are :

  • 12,13,14 , 12 is father directory
  • 13 inside 12 , 14 inside 13
  • david1.txt inside 14
  • get_current_dir_name() is a Linux function , not mine

I run the executable file from Desktop , like this (here are printf-s for trying to locating the problem) :

    // doesn't work 

   a@ubuntu:~/Desktop$ ./exer4 12 david1.txt

    Current path is :12

    Current path is :/home/a/Desktop/12/13

    Current path is :/home/a/Desktop/12/13/14

//////////////////////////////////////////////////
    // doesn't work      

    a@ubuntu:~/Desktop$ ./exer4 12/13 david1.txt

    Current path is :12/13

    Current path is :/home/a/Desktop/12/13/14

////////////////////////////////////////////////
    // doesn't work 

    a@ubuntu:~/Desktop$ ./exer4 12/13/14 david1.txt

    Current path is :12/13/14

If I remove these lines :

chdir(path);                          // the problem is probably here 
strcpy(path, get_current_dir_name()); // and here 

Then every query that involves only a single library name – works , for example :

// works : 

a@ubuntu:~/Desktop$ ./exer4 12 david1.txt

Current path is :12

Current path is :12/13

File found!

12/13/14/david1.txt-rw-rw-r-- 1 1000 1000 0 2012-06-17 08:10 

Current path is :12/13/14
////////////////////////////////////////////////////////////
// works 
a@ubuntu:~/Desktop$ ./exer4 12/13 david1.txt

Current path is :12/13

File found!

12/13/14/david1.txt-rw-rw-r-- 1 1000 1000 0 2012-06-17 08:10 

Current path is :12/13/14

////////////////////////////////////////////////////////////
// Doesn't work
a@ubuntu:~/Desktop$ ./exer4 12/13/14 david1.txt

Current path is :12/13/14

Any idea what I’m doing wrong here ? I’ve tried to change countless times but nothing fixed it . Thanks

  • 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-05T21:51:44+00:00Added an answer on June 5, 2026 at 9:51 pm

    When doing strcpy(path, get_current_dir_name()), you don’t check that the buffer isn’t exceeded.
    If path is argv[1], you’re overrunning the stack.
    My guess is that you overrun the file name (argv[2]), and then you start looking for the wrong name (and don’t find it).

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

Sidebar

Related Questions

Hi good people once again While busy traversing, iterating and manipulating my arrays from
I have a 5yr old G4 PowerBook that I use while travelling, and I
While making some final tests of a class-library that I'm writing for Windows Mobile
While trying to verify to myself, that C# Equals for IEnumerables is a reference
While trying to implement an MVC file upload example on Scott Hanselman's blog. I
I have a function using $.ajax() to get values from an XML file, when
How to keep track of the level while traversing a binary tree in level
I am having a tree data structure that can have different types of nodes
I'm basically trying to create a linked list from a text file and add
I'm new to XML parsing and want to convert XML file resulting from a

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.