Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

convert from int to const char *

Hi all
Please, can anyone help me
I want to write utility program to create multi directory
The compile gives me this message :
cannot convert from 'int' to 'const char *

int stat;
for (int i=1;i<=10;i++)
stat=mkdir(i);


So sorry if the question very basically but, I am beginner
Thank
[358 byte] By [Mansur] at [2007-11-11 8:16:48]
# 1 Re: convert from int to const char *
mkdir takes a char *, i.e. a directory name. You can't pass an integer as a name. You ned to covert it first to a string using a conversion functions such as sprintf() or a similar function.
Danny at 2007-11-11 21:01:30 >
# 2 Re: convert from int to const char *
Thank Danny

My code is work now
I am use vc++

char buffer [10];

for (int i=1;i<=10;i++)
{
sprintf (buffer, "%d",i);
UpdateData(true);
m_edit1= buffer;
UpdateData(false);
stat=mkdir(buffer);
}

Note :
Please, you know other way to create directors best then that?

Mansur
Mansur at 2007-11-11 21:02:31 >
# 3 Re: convert from int to const char *
mksir is the only portable interface for creating directories. You can try to use the Boost directory library but to do that you will need to install that library from www.boost.org. I'm not sure it's worth the trouble in your case since all you need to do is create multiple directories with a changing name.
Danny at 2007-11-11 21:03:30 >
# 4 Re: convert from int to const char *
Thank again Danny
Mansur at 2007-11-11 21:04:29 >