Question
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
#include
#include
#include
int main(int argc, char *argv[])
{
int fd;
if ( argc < 2 ){
printf("Usage: %s
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started