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
a transmitter is operating at 150 MHz with a power of 3 W into a one-quarter wavelength vertical antenna. The receiver, which is
Bogdan [553]

The received power will be 1.243 nW

We're given:

frequency f = 150MHz

distance of the receiver d = 32.2 km=32200m

Power of transmitter P_{t} = 3W

Antenna gain = 8dB

To find :

Power received P_{r}

P_{r}= \frac{P_{t} *G_{t}*G_{r}* \lambda^2 }{16*\pi^2*d^2}

where G_{t is transmit gain and G_{r is receive gain as refrenced to isotropic source

⇒wavelength \lambda = \frac{c}{f} where c is the speed of the light

⇒  \lambda = \frac{3*10^8}{150*10^6} =2m

G_{t}= 1*1.64 ( value of dipole = 1.64)

Now,

Antenna gain=8dB ( in decibals)

⇒10log(x)=8

⇒x=10^0^.^8=6.3095

⇒ considering isotropic receiver

⇒G_{r}=6.3095*1.64=10.3477 (dipole =1.64)

Now , using the formula

P_{r}= \frac{3 *1.64*10.3477 *2^2 }{16*\pi^2*32200^2}=1.2437*10^-^9

Hence The received power will be 1.243 nW

Leaen more about communication devices here:

brainly.com/question/14530107

#SPJ10

4 0
2 years ago
If you enter 234.567 into a cell that is formatted to display 1 decimal place, what is the value stored in the cell?
Jobisdone [24]
Answer C because you would round up to .6 since that is the tenths (aka the first) decimal place
4 0
3 years ago
____ are made up of related records.
Delvig [45]

Answer:

Tables are made up of related records.

Explanation:

8 0
3 years ago
An operations information system typically accesses data gathered by a _____ system and converts the data into useful informatio
Darina [25.2K]
Answer: Operating System 
6 0
3 years ago
In the context of network effects, the term "network" refers to either wired or wireless systems that connect computing componen
AnnZ [28]
<span> The term network effect describes the concept in which increased numbers of people or participants improve the value of a good or service. </span><span>
The statement that in the context of network effects, the term "network" refers to either wired or wireless systems that connect computing components is false.</span>
3 0
3 years ago
Other questions:
  • What type of lens was used to take this picture?
    15·1 answer
  • What is an input, output and storage device?
    12·1 answer
  • Jason is making a presentation on power dressing. Jason completes the presentation on his laptop. However, on the day of deliver
    9·2 answers
  • A client has an issue with large files taking a long time to open or save. As time goes by, the issue worsens. The client has hu
    8·1 answer
  • Stan’s assignment is to print a three-dimensional image on a piece of paper. Which printing technique should he use?
    14·2 answers
  • LotR Trivia- 1. What does LotR stand for?
    13·1 answer
  • How can rows be added to a table? Check all that apply.
    15·2 answers
  • Priscilla is providing the junior analysts, in her firm, on the team with some real-world illustrations to explain some of the r
    9·1 answer
  • What is a bitmap ???
    13·2 answers
  • How does xm satellite deter nonsubscribers from listening to its transmissions? Does this make the radio programing a private go
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!