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(>odTimes[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(>odTimes[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(>odTimes[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);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.