Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume that invisible _file is NOT in the current directory where you execute the following code, so it will give you the error using perror

Assume that invisible _file is NOT in the current directory where you execute the following code, so it

will give you the error using

perror

function. The purpose of this lab is to help you understand

perror.

--perror_file.c-------------------------

#include

#include // for exit() function

#include

#include

#include

int main(int argc, char *argv[])

{

int fd;

if ( argc < 2 ){

printf("Usage: %s \ n", argv[0]);

printf("The file might exist or not.\ n");

exit(1);

}

fd = open(argv[1], O_RDONLY);

// printf will output user's formatted string, while perror will output

// the system error msg corresponding to errno

if (fd == -1){

printf("Opening file \ "%s\ " failed.\ n", argv[1]);

}

else{

printf("The file \ "%s\ " was opened w/o problem.\ n", argv[1]);

}

return 0;

}

Modify the code so that it will try to change to a directory rather than access a file. What error did you get?

Use perror appropriately in the code to show the error.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions