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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 19:50, rosyposy43
Write a car class having two private member variables called tank and speed. write public methods called pumpgas and gofast. the method pumpgas gets an integer for gas that must be pumped. that value needs to be added to tank (no more than 20 gallons). it must return the amount of gas that is purchased ($4 per gallon). the method gofast should increase the speed by 5 each time it is called. write a constructor for the above class that initialized both variables to zero. write a tostring to display both the tank and speed when the car is printed. modify the car class to implement the interface comparable and an interface called carinter having the public methods in carinter. write the main program to create an array of size 5 of type car. create 5 car objects having each location of the array to refer to one of the cars. test the pumpgas, gofast, equals method on the array items. write an enhanced loop to print all the car values (using a tostring written last time).write a generic method to find the minimum of four items. pass int, double, char, string and car objects to test this method.
Answers: 1
image
Computers and Technology, 24.06.2019 03:40, Eylul30
4. does the kernel phenotype distribution support the idea that the cob is the result of a dihybrid cross? what information supports your answer? if a dihybrid cross (i. e. f1 to f2 of standard mendelian crosses) is not indicated what conditions might contribute to this finding.
Answers: 2
image
Computers and Technology, 24.06.2019 09:50, potatocow
Self contained sequences of actions to be performed are? a. expressions b. algorithms c. functions d. formulas
Answers: 1
image
Computers and Technology, 24.06.2019 22:00, dixks
According to your study unit, what is the main reason that improved human relations skills may improve your grades?
Answers: 1
You know the right answer?
Snippet 1: check_file_permissions. c #include 1
#include
#include
int main (int...

Questions in other subjects:

Konu
Geography, 20.08.2019 20:30
Konu
Biology, 20.08.2019 20:30