Skip to content

Instantly share code, notes, and snippets.

@PhDP
Created February 4, 2012 15:26
Show Gist options
  • Save PhDP/1738481 to your computer and use it in GitHub Desktop.
Save PhDP/1738481 to your computer and use it in GitHub Desktop.
Create a directory in C
// gcc main.c -o main
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
int main()
{
mkdir("newdir", S_IRWXU); // S_IRWXU is the mode, it gives read/write/search access to the user.
FILE *out = fopen("newdir/newfile.txt", "w");
fprintf(out, "Hello new directory!\n");
fclose(out);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment