subject

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.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 23:00
The animal classthis class represents a an animal residing at a zoo. it has a weight (in pounds),height (in inches), a name, and a color. the methods in the class include constructors,getters, and a tostring. you will finish the implementation of these methods. referto the code documentation.1.getters: you will need to implement getter methods. these get a value (froma member variable) in the animal class. you will make a getter method toreturn each variable (weight, height, name, color). reference getname if youare having issues.2.tostring: you will need to finish the tostring method. this returns a stringcontaining information about an animal. the output string should be of theformat: ” (name) , a ( color )â’colored animal . ( weight ) pounds , ( height ) inches .\n”the height and weight are formatted to 1 decimal place. recall from lab 1how to format strings neatly using string. see the reference sectionfor more about string.format.
Answers: 2
question
Computers and Technology, 22.06.2019 04:30
How can you know if the person or organization providing the information has the credentials and knowledge to speak on this topic? one clue is the type of web site it is--the domain name ".org" tells you that this site is run by a nonprofit organization.
Answers: 2
question
Computers and Technology, 22.06.2019 13:30
Write lines of verse that rhyme to remember the following information: acid rain is a type of air pollution caused by chemicals in the air.
Answers: 1
question
Computers and Technology, 22.06.2019 21:00
So im doing this school challenge and the teachers said whats the average text a student gets a day so i need to get about 20 in a day but dont know how can you guys 2163371293
Answers: 2
You know the right answer?
Snippet 1: check_file_permissions. c #include 1
#include
#include
int main (int...
Questions
Questions on the website: 13722362