1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
snow_tiger [21]
3 years ago
9

Write a C program to implement a command called ​displaycontent ​that takes a (text) file name as argument and display its conte

nts. 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
Computers and Technology
1 answer:
Zanzabum3 years ago
7 0

Answer:

/*

Student: Hugo Meza

Date: February 15, 2019

Description: This program mimic the cat command from Linux. Checks whether the source file

has the right permissions, and then writes in the console its content.

*/

#include <stdio.h>

#include <fcntl.h>

#include <unistd.h>

#include <errno.h>

int hasPermission(char *filepath){

int returnval;

// Check file existence

returnval = access (filepath, F_OK);

if(errno == ENOENT){

printf ("%s does not exist\n", filepath);

return 0;

}

else if (errno == EACCES){

printf ("%s is not accessible\n", filepath);

return 0;

}

// Check read access

returnval = access (filepath, R_OK);

if(errno == ENOENT){

printf ("%s does not have read access\n", filepath);

return 0;

}

else if (errno == EACCES){

printf ("%s is not accessible\n",filepath);

return 0;

}

// Check write access

returnval = access (filepath, W_OK);

if(errno == ENOENT){

printf ("%s does not have read access\n", filepath);

return 0;

}

else if (errno == EACCES){

printf ("%s is not accessible\n",filepath);

return 0;

}

return 1;

}

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

if(!argv[1]){

printf("Error. Specify file to open\n");

return 0;

}

int fd;

char *fp = argv[1], content[fd];

if(hasPermission(fp) == 0)

return 1;

fd = open(fp, O_RDONLY);

int bytes = read(fd,content,sizeof(content)-1);

write(1, content, bytes);

close(fd);

return 0;

}

Explanation:

You might be interested in
What is the single most important component of a computer? Central Processing Unit DIP Motherboard Chipset
Dominik [7]
The mother board it holds all of the storage
5 0
3 years ago
Question 7 Consider the following code:
zhannawk [14.2K]

Answer:

Melon

Explanation:

The variable "list" containts a function that returns a price that is greater than or equal to 60.0.

In the variable "fruit", the only item in the array with a price attribute set above that number is the string Melon.

3 0
1 year ago
A technician has been dispatched to a customer site to diagnose an issue where the computer turns off intermittently. Upon arriv
alisha [4.7K]

Answer:

The answer is "Option B".

Explanation:

When the technician detects a smoke smell, which is coming from the computer system it means it will sort to solve this problem the technician will shut the system down and substitute electricity, at this, it overcomes the problem, and wrong choices can be defined as follows:

  • In choice A, It is wrong because in this system component may be destroyed.
  • In choice C and D both are wrong because it is not a software and side panel problem.-
6 0
3 years ago
The Internet has made it possible for most people to order all of their clothing online. While this may be a preference for some
suter [353]

Answer:

Explanation:

Based on the information provided in this scenario it can be said that this is likely due to there being a cultural lag between having the Internet and using the technology to its full capacity. Cultural lag refers to the notion that culture takes time to catch up with technological innovations, mainly due to not everyone has access to the new technology. As years pass a specific technological advancement becomes more readily accessible to the wider public as is thus more widely adopted.

3 0
3 years ago
Jason is working on a project that requires him to manage a huge amount of data. The spreadsheet he is working on has data relat
Alinara [238K]

A. use split worksheet view to break the worksheet into different visible sections

<u>Explanation:</u>

Jason is working on a project that requires him to manage a huge amount of data. There are numerous instances when a user has to manage a huge amount of data within a single spreadsheet. It will cause trouble for the user to simultaneously access the data from more than one table in the same sheet.

To deal with this problem, Jason can track and compare this data as he works on the spreadsheet by using the split worksheet view to break the worksheet into different visible sections. The different sections provide a better view of the tables and data extraction and manipulation become easy.

6 0
3 years ago
Other questions:
  • 7. Which innovation in video games do you think has been most significant? Include at least one way that innovation affects the
    6·1 answer
  • Which phrase is a comparison operator for inserting a not equal to argument in an IF, COUNTIF or SUMIF function? &lt;= &lt;&gt;
    9·1 answer
  • The ability to anticipate and determine upcoming driving hazards and conditions are adversely affected
    14·1 answer
  • Which of these ia an example of gene flow?
    5·1 answer
  • Briefly describe the traditional definition of the digital divide. What is it and who is affected, positively and adversely? How
    15·1 answer
  • You are the IT administrator for a small corporate network. The employee in Office 2 is setting up a virtualization environment
    10·1 answer
  • What does the following process describe?
    10·1 answer
  • state an application that would be better to write c++ than java and give a rationale for your answer
    5·1 answer
  • a value-returning method must specify as its return type in the method header. question 18 options: a) an int b) a double c) a b
    9·1 answer
  • Bluetooth is the popular name for the 802. 15 wireless networking standard, which is useful for creating small __________.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!