Question

Create the following subdirectory structure under your home directory using Program 1.                            &nbsp

Create the following subdirectory structure under your home directory using Program 1.

                                                                        Subdir1

              -------------------------------------------------------------------------------------------------

              |                                                           |                                                                   |

              D1                                                     d2                                                                   d3

--------------------------------              --------------------------------------                    --------------------------------------

|                   |                    |            |                     |                          |                    |                       |                         |

A1.txt      A2.txt        A3.txt      B1.ccc              B2.ccc            B3.ccc         C1.txt                 C2.ddd               C3.txt

Create a C function with the following capabilities:

Program 1:

  1. Create “Subdir1” directory with permission 0766
  2. Create sub-directories “D1”, “d2”, and “d3” under the directory “Subdir1” with permission 0777
  3. Under the directory “D1” create the following files with permission 0666 :
    1. “A1.txt” and write “abcdefghij”
    2. “A2.txt” and write “you are beautiful”
    3. “A3.txt” and write “this is terrible!”
  4. Under the directory “d2” create the following files with permission 0664:
    1. “B1.ccc” and write “abcdefghij”
    2. “B2.ccc” and write “you are beautiful”
    3. “B3.ccc” and write “this is terrible!”
  5. Under the directory “d3” create the following files with permission 0644:
    1. “C1.txt” and write “abcdefghij”
    2. “C2.ddd” and write “you are beautiful”
    3. “C3.txt” and write “this is terrible!”
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

#include<conio.h>

#include<dir.h>

void main() {

char path1 = "/home/Subdir1"; // path for subdirectory under your home directory

int res;

res = mkdir(path1, 0777); // create the directory using mkdir function

if(!res) {

printf("Directory created successfully");

}

else {

printf("Error in creating directory");

exit(1);

}

//creating subdirectors D1, d2, and d3 under Subdir1 with permision 0777

char path2 = "/home/Subdir1/D1";

char path3 = "/home/Subdir1/d2";

char path4 = "/home/Subdir1/d3";

res2 = mkdir(path2, 0777);

res3 = mkdir(path3, 0777);

res3 = mkdir(path4, 0777);

FILE * fptr; // create a file pointer

char str[] = "abcdefghij";

fptr = fopen("/home/Subdir1/D1/A1.txt", "w", 0666); // open the file A1.txt in write mode with 0666 permission

for(i=0;str[i]!='\n';i++){

fputc(str[i],fptr); // write the content to file using fputc

}

fclose(fptr); // close the file pointer

char str1[] = "you are beautiful";

fptr = fopen("/home/Subdir1/D1/A2.txt", "w", 0666); // open the file A2.txt in write mode with 0666 permission

for(i=0;str1[i]!='\n';i++){

fputc(str1[i],fptr); // write the content to file using fputc

}

fclose(fptr); // close the file pointer

char str2[] = "this is terrible!";

fptr = fopen("/home/Subdir1/D1/A2.txt", "w", 0666); // open the file A2.txt in write mode with 0666 permission

for(i=0;str2[i]!='\n';i++){

fputc(str2[i],fptr); // write the content to file using fputc

}

fclose(fptr); // close the file pointer

char strB[] = "abcdefghij";

fptr = fopen("/home/Subdir1/d2/B1.ccc", "w", 0664); // open the file B1.ccc in write mode with 0664 permission

for(i=0;strB[i]!='\n';i++){

fputc(strB[i],fptr); // write the content to file using fputc

}

fclose(fptr); // close the file pointer

char strB2[] = "you are beautiful";

fptr = fopen("/home/Subdir1/d2/B2.ccc", "w", 0664); // open the file B2.ccc in write mode with 0664 permission

for(i=0;strB2[i]!='\n';i++){

fputc(strB2[i],fptr); // write the content to file using fputc

}

fclose(fptr); // close the file pointer

char strB3[] = "you are terrible!";

fptr = fopen("/home/Subdir1/d2/B3.ccc", "w", 0664); // open the file B3.ccc in write mode with 0664 permission

for(i=0;strB3[i]!='\n';i++){

fputc(strB3[i],fptr); // write the content to file using fputc

}

fclose(fptr); // close the file pointer

}

Add a comment
Know the answer?
Add Answer to:
Create the following subdirectory structure under your home directory using Program 1.                            &nbsp
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT