Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do you get these three files to work together as one? Any help would be appr

ID: 3679185 • Letter: H

Question

How do you get these three files to work together as one? Any help would be appreciated...

TEST

#include <stdio.h>

#include <sys/time.h>

#define N   10

#define LENGTH   80

main(int argc, char **argv)

{

FILE *clockMod;

struct timeval gtodTimes[N];

char *procClockTimes[N];

int i;

for(i=0; i<N; i++) {

    gettimeofday(&gtodTimes[i], 0);

    if((clockMod = fopen("/proc/clock","r")) == NULL) {

      printf("open failed, terminating ");

      exit(0);

    }

    procClockTimes[i] = (char *) malloc(LENGTH+1);

    fgets(procClockTimes[i], LENGTH, clockMod);

    close(clockMod);

    sleep(1);

}

/* Print results */

printf("gettimeofday()   Clock Module ");

for(i=0; i<N; i++) {

    printf(" %d %d   %s ",

       gtodTimes[i].tv_sec, gtodTimes[i].tv_usec, procClockTimes[i]);

}

}

CLOCK

#include <stdio.h>

#include <sys/time.h>

#define N   10

#define LENGTH   80

main(int argc, char **argv)

{

FILE *clockMod;

struct timeval gtodTimes[N];

char *procClockTimes[N];

int i;

for(i=0; i<N; i++) {

    gettimeofday(&gtodTimes[i], 0);

    if((clockMod = fopen("/proc/clock","r")) == NULL) {

      printf("open failed, terminating ");

      exit(0);

    }

    procClockTimes[i] = (char *) malloc(LENGTH+1);

    fgets(procClockTimes[i], LENGTH, clockMod);

    close(clockMod);

    sleep(1);

}

/* Print results */

printf("gettimeofday()   Clock Module ");

for(i=0; i<N; i++) {

    printf(" %d %d   %s ",

       gtodTimes[i].tv_sec, gtodTimes[i].tv_usec, procClockTimes[i]);

}

}

MAKEFILE

#

# Makefile for gettimeofday module

#

CFLAGS = -c -Wall -D__KERNEL__ -DMODULE

CC = gcc

.c.s:

   $(CC) $(CFLAGS) -S $<

.s.o:

   $(AS) -c -o $*.o $<

.c.o:

   $(CC) $(CFLAGS) -c $<

OBJS = clock.o

SRCS = clock.c

MODULES = clock.o

all: $(OBJS)

Explanation / Answer

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

#include <sys/time.h>

#include <unistd.h>

#define N 25

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

FILE *fp;

struct timeval gtodTimes[N];

char *procClockTimes[N];

int i=0, LENGTH = 25;

time_t now;

/*Get current time*/

  now = time(NULL);

  printf(" Status report at %s ", ctime(&now));

printf(" test");

  fp = fopen("/proc/clock", "r");

  for (i=0; i<N; i++){

    gettimeofday(&gtodTimes[i],0);

    fgets(procClockTimes[i], LENGTH, fp);

  }

  for (i=0; i<N; i++){

    printf("The time of day is %d and something %s", gtodTimes[i],

procClockTimes[i]);

}

  fclose(fp);

  exit(0);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote