How to create a new directory in C

M

Mark McIntyre

Are you sure about that?

Yes:
7.20.4.6 The system function
If string is not a null pointer, the system function passes the string
pointed to by string to that command processor to be executed in a manner
which the implementation shall document;
The C standard says:

(something irrelevant about escape sequences).

The important word is "intended". There's nothing there to mandate it to do
anything for which the C standard generally uses "shall".
 
D

Dik T. Winter

>
> Are you sure about that? The C standard says:

Oh, Mark is pretty sure. The string passed to the system contains a
formfeed, what happens with that string is implementation defined.
On this system: system("ls > c:\\foo.txt"), will create a file where
the name contains a formfeed.
 
P

pete

Mark said:
See previous answer.

I was thinking of your previous answer.

Whether or not that string contains a formfeed is highly on topic,
and maybe not obvious to some people, like yourself.
 
J

Joona I Palaste

Oh, Mark is pretty sure. The string passed to the system contains a
formfeed, what happens with that string is implementation defined.
On this system: system("ls > c:\\foo.txt"), will create a file where
the name contains a formfeed.

Dik, are you having a typo day? I recently spotted one typo from you on
sci.math, and now you have another. There's no formfeed character in
"ls > c:\\foo.txt". Did you mean "ls > c:\foo.txt"?
 
M

Mark McIntyre

I was thinking of your previous answer.

Whether or not that string contains a formfeed is highly on topic,
and maybe not obvious to some people, like yourself.

The presence of single-character escape sequences in strings is something
that's been obvious to me since around 1986, when I first programmed C (on
a Vax 8700 I think it was, tho th Atari ST1024 came around the same time).
Thats not the point.
 
D

Dik T. Winter

> Dik T. Winter <[email protected]> scribbled the following: ....
>
> Dik, are you having a typo day? I recently spotted one typo from you on
> sci.math, and now you have another. There's no formfeed character in
> "ls > c:\\foo.txt". Did you mean "ls > c:\foo.txt"?

Yup. 7 November is typo day.
 
C

caroundw5h

Wow, does anything ever get done around here?

Code:
#include <stdio.h>
#include <stdlib.h>// for system
int main(void)
{
system("md HEREIAM");
system("mkdir PICKABOO");
return 0;
}

compile the following on windows save it in the C: directory then go
back and look for the file names passed as arguments.
or if you want you can pass the path to system after md:
ex: md path\kdkdk\kdkdk\kkdkd


or just #include <windows.h>
and use CreateDirectory("path to dir");
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
(e-mail address removed) (caroundw5h) wrote in message
Wow, does anything ever get done around here?

Code:
#include <stdio.h>
#include <stdlib.h>// for system
int main(void)
{
system("md HEREIAM");
system("mkdir PICKABOO");
return 0;
}

compile the following on windows save it in the C: directory then go
back and look for the file names passed as arguments.
or if you want you can pass the path to system after md:
ex: md path\kdkdk\kdkdk\kkdkd



or just #include <windows.h>
and use CreateDirectory("path to dir");

Hmmm... I don't think that works.

~/code $ cat mdir.c
#include <windows.h>

int main(void)
{
CreateDirectory("/home/lpitcher/newdirectory");

return 0;
}
~/code $ cc -o mdir mdir.c
mdir.c:1:21: windows.h: No such file or directory
~/code $ uname -a
Linux bitsie 2.4.26 #7 Mon Apr 19 23:43:43 EDT 2004 i686 unknown

Apparently, the "windows.h" include file isn't part of the gcc compiler kit.
Obviously, it's not part of standard C, otherwise it would have been included
in gcc.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBjtB6agVFX4UWr64RApjjAKDpwOa4/t4WphldLtYF4/5+FioflgCgrKjV
uX8jutsqubx6rPVhFCtXNFI=
=OxL4
-----END PGP SIGNATURE-----
 
B

Ben Pfaff

Lew Pitcher said:
Apparently, the "windows.h" include file isn't part of the gcc compiler kit.
Obviously, it's not part of standard C, otherwise it would have been included
in gcc.

GCC does not include a C library.
 
W

wangxiaopeng1976

I found using cygwin and this code,
it can create the directory PICKABOO.

If using MKS, both can created.
 
R

Richard Bos

Wow, does anything ever get done around here?
Certainly.

#include <stdio.h>

You never use this header. Eradicate it.
#include <stdlib.h>// for system

No, really? I wonder what kind of comment you write when you use a dozen
functions from a header.
int main(void)
{
system("md HEREIAM");
system("mkdir PICKABOO");

If you go back in the thread, you'll see that that is _exactly_ what the
OP was doing. His problem was that it appeared not to work.

Richard
 
P

pete

Richard said:
(e-mail address removed) (caroundw5h) wrote:

No, really? I wonder what kind of comment
you write when you use a dozen functions from a header.

I used to comment things like that,
until after about two weeks of learning C.
 
M

Michael Mair

pete said:
I used to comment things like that,
until after about two weeks of learning C.

And I still do, sometimes, when I have dozens of headers and want to
know which is needed for what. The data structures are all in one but
some of the access macros added later on found their way into another
header (by way of the corresponding translation unit).
When doing solutions for C newbies, I also write these comments so
they learn that they "need headerxyz for function abc" and the like.

For my own, private stuff, I do not use this comment style.
Nonetheless, I at least group my headers.


Cheers
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top