Computers and Technology

Snippet 1: check_file_permissions. c #include 1
#include
#include
int main (int argc, char* argv[])
{ char* filepath = argv[1];
int returnval;
// Check file existence returnval = access (filepath, F_OK);
if (returnval == 0) printf ("\n %s exists\n", filepath);
else { if (errno == ENOENT) printf ("%s does not exist\n", filepath);
else if (errno == EACCES) printf ("%s is not accessible\n", filepath);
return 0; }
// Check read access ...
// Check write access ...
return 0;
}
0.
(a) Extend code snippet 1 to check for read and write access permissions of a given file
(b) Write a C program where open system call creates a new file (say, destination. txt) and then opens it. (Hint: use the bitwise OR flag)
1. UNIX cat command has three functions with regard to text files: displaying them, combining copies of them and creating new ones.
Write a C program to implement a command called displaycontent that takes a (text) file name as argument and display its contents. Report an appropriate message if the file does not exist or can’t be opened (i. e. the file doesn’t have read permission). You are to use open(), read(), write() and close() system calls.
NOTE: Name your executable file as displaycontent and execute your program as ./displaycontent file_name
2. The cp command copies the source file specified by the SourceFile parameter to the destination file specified by the DestinationFile parameter.
Write a C program that mimics the cp command using open() system call to open source. txt file in read-only mode and copy the contents of it to destination. txt using read() and write() system calls.
3. Repeat part 2 (by writing a new C program) as per the following procedure:
(a) Read the next 100 characters from source. txt, and among characters read, replace each character ’1’ with character ’A’ and all characters are then written in destination. txt
(b) Write characters "XYZ" into file destination. txt
(c) Repeat the previous steps until the end of file source. txt. The last read step may not have 100 characters.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 02:00, kelseybell5522
For a typical middle-income family, what is the estimated cost of raising a child to the age of 18? $145,500 $245,340 $304,340 $455,500
Answers: 1
image
Computers and Technology, 23.06.2019 07:00, lin550
Why were most movies from the late 1890s until the early 1930s only filmed in black and white? there were only a few people who could afford the technology to produce color motion pictures back then. audiences did not want color motion pictures until later. the film used to make color motion pictures often overheated, which was a safety hazard, so it was generally not allowed. color films had to be hand-colored, frame by frame.
Answers: 3
image
Computers and Technology, 23.06.2019 14:00, uday50
Select the correct answer. a company is currently focusing on creating specific management goals for itself. which level of maturity is the company demonstrating under the sse_ccm framework? a. performed informally b. planned and tracked c. quantitatively controlled d. well-defined e. continuously improving
Answers: 2
image
Computers and Technology, 23.06.2019 15:00, hunteryolanda82
Based on the current economic situation do you expect the employment demand for graduating engineers to increase or decrease? explain the basis for your answer. with a significant economic recovery, what do you think will happen to future enrollments in graduating engineering programs?
Answers: 1
Do you know the correct answer?
Snippet 1: check_file_permissions. c #include 1
#include
#include
int main (int...

Questions in other subjects:

Konu
Physics, 08.04.2021 04:40
Konu
Mathematics, 08.04.2021 04:40