Q:
C program to create a directory using mkdir() function
belongs to collection: File Handling Examples Programs in C language
File Handling Examples Programs in C language
- C program to find number of lines in a file
- C program to create a text file using file handling, example of fopen, fclose
- C program to create, write and read text in/from file
- C program to print given number of lines of a file (like head command in Linux)
- C program to print contents in reverse order of a file (just like TAC command in Linux)
- C program to compare contents of two files
- C program to copy number of bytes from specific offset to another file
- C - Read Content of a File using getc() using C Program
- C - Convert All Characters in Upper Case of a File using C Program
- C program to delete a specified file using remove() function
- C program to delete a specified file using the system() function
- C program to remove a specified empty directory using the remove() function
- C program to remove an empty directory
- C program to remove a non-empty directory using the system() function
- C program to check a given filename is a directory or not
- C program to remove a specific line from the text file
- C program to replace the specified line in an existing text file
- C program to append the content of one file to the end of another file
- C program to print the list of files of a directory
- C program to print the list of files and subdirectories of the current directory
- C program to check a specified directory exists or not
- C program to check a specified file exists or not
- C program to check a specified file exists or not using the stat() function
- C program to check a specified file exists or not using the access() function
- C program to check a specified file has read, write, and execute permission or not
- C program to create a directory using mkdir() function
- C program to create a directory using system() function
- C program to remove an empty directory using rmdir() function
- C program to rename a file using the rename() function
- C program to rename a file using the system() function
- C program to change the permissions of file using system() function
- C program to capitalize the first letter of every word in a file
Input the name (path) of the directory, and then we will create the given directory using the mkdir() function.
The mkdir() function is library function of <sys/stat.h> header file which is used to create a new directory with a new path.
Syntax:
The argument path defines the path of the directory, and the mode specifies the file permissions for the new directory file.
The function returns 0 if the directory created successfully, or -1 on failure.
Program:
The source code to create a directory using the mkdir() function is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
Output:
Explanation:
Here, we created a character array dirName. Then we read the name of the directory from the user. Then we created the given directory using the mkdir() function and printed the appropriate message on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer