Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mkdir problem

Status
Not open for further replies.

newbieKing

Programmer
Jan 29, 2003
19
0
0
CA
Hi, I've got a problem with my mkdir function. After I call mkdir a string called "file_name" gets altered.
Do you have any idea what is going on?

cout << file_name << "\n"; // name displayed
mkdir(output_dir);
cout << file_name << "\n"; // name not displayed

Thank you!
 
What are file_name and output_dir? Are they const char*, CString, std::string?
 
they are both

char *

a character pointer. I did not declare them as const... do I need to?
 
How does it get altered? What is the value of file_name before and after calling mkdir()?
What OS and compiler are you using?

Can you write a short example program that we can compile and test which displays this behavior?
(also, put code inside [ignore]
Code:
[/ignore] tags)
 
I declare the variables globally in a .h file:

/* files and directories */
const char * output_dir;
const char * perfusion_file;

My “file_name” is actually called “perfusion_file”. In my main program I have:

int main(int argc, char** argv)
{
assign_vars(argc, argv); // assigns variables here

cout << "Perfusion Out1: " << perfusion_file << "\n";

mkdir(output_dir);
cout << "Perfusion Out2: " << perfusion_file << "\n";

chdir(output_dir);
cout << "Perfusion Out3: " << perfusion_file << "\n";


}

In the output I get:

Perfusion Out1: F:\source\thermal\simmulti\const15.perf
Perfusion Out2:
Perfusion Out3: Ãyøwà>

I’m using VC++ on Windows 2000.

Do you have any idea what is wrong?

Thank you.

 
If you print output_dir before and after mkdir(), what does it say?
 
Hello,

The output file string does not seem to change:

Output file before: F:\code\practice_code\Input_GUI_dynamic\output
Output file after: F:\code\practice_code\Input_GUI_dynamic\output

Any ideas?

Thanks!
 
So what is the problem?

/Per
[sub]
www.perfnurt.se[/sub]
 
Hi,

It seems like I have a pointer problem...

Here is my code:
I declare a global char pointer in a .h file:
char * output_dir;

then in the main I print that dir:
cout << output_dir << end;
cout << &output_dir << end;
cout << output_dir << end;

The output is:
F:\source\thermal\simmulti\p3d_015.bnd
0042A900
F:\source\therma

Is my use of pointers totally wrong??
 
More like a stack problem. What does assign_vars do?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top