Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fix the following code in UNIX, i will give you a good rating #include<stdio.h>

ID: 3700850 • Letter: F

Question

Fix the following code in UNIX, i will give you a good rating

#include<stdio.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<stdlib.h>


int main()
{
int ret = 0;
int fd1 = 0, fd2 = 0;

//Creating main directory named "A4PART1"
ret = mkdir("./A4PART1",0766);
if(ret != 0){
fprintf(stderr,"Unable to create directory "A4PART1" ");
perror("A4PART1: ");
return -1;
}

//Creating folder1 inside A4PART1
ret = mkdir("./A4PART1/folder1",0766);
if(ret != 0){
fprintf(stderr,"Unable to create directory "folder1" ");
perror("Folder1: ");
return -1;
}

//Creating folder2 inside A4PART1
ret = mkdir("./A4PART1/folder2",0766);
if(ret != 0){
fprintf(stderr,"Unable to create directory "folder2" ");
perror("Folder2: ");
return -1;
}

//Creating file1.txt inside folder1
fd1 = open("./A4PART1/folder1/file1.txt",O_CREAT, 0644);
if(fd1 < 0){
fprintf(stderr,"Unable to create file1.txt ");
perror("File1: ");
return -1;
}

//Creating file2.txt inside folder2
fd2 = open("./A4PART1/folder2/file2.txt",O_CREAT, 0644);
if(fd2 < 0){
fprintf(stderr,"Unable to create file2.txt ");
perror("File2: ");
return -1;
}

//Create a symlink in "A4PART1" to "file2.txt"
ret = symlink("folder2/file2.txt", "./A4PART1/link4");
if(ret != 0){
fprintf(stderr,"Unable to create symlink link4 ");
perror("link4: ");
return -1;
}

close(fd1);
close(fd2);
return 0;
}

Explanation / Answer

There is no error in this program.

In my linux system the code is compiled successfully and and folders and files are created successfully.