f
unknown
plain_text
3 years ago
2.5 kB
9
Indexable
// CITS2002 Project 1 2022
// Student1: 23258746 CHANG ESTHER YEE VUN
// Student2: 23297983 MITRA SREELAJOYOTI
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX 100
struct Cron {
char Minutes[3];
char Hours[3];
char Days[3];
char Months[4];
char DayOfWeek[4];
char Command[40];
};
struct DayTime {
int Day;
int Minute;
};
struct CommandExecution {
char Command[30];
struct DayTime Start;
struct DayTime End;
};
struct Estimate {
char Command[40];
int Minutes;
};
int check_date(int day, int month){
}
int main()
{
FILE *ef;
FILE *ctf;
char ch;
//int line_count =0;
//char line[MAX];
char dates[MAX];
char *delim =" ";
char array[MAX];
int n1;
int n2;
// Opening file in reading mode
//ef = fopen("estimates-file.txt", "r");
ctf = fopen("crontab-file.txt","r");
if (NULL == ctf) {
printf("file can't be opened \n");
exit(EXIT_FAILURE);}
char buffer[300];
char* line = buffer;
size_t len;
size_t size = 0;
struct Cron crons[100];
int i = 0;
while((size = getline(&line, &len, ctf)) != -1) {
if (line[0] == '#') {
continue;
}
else if (size > 1) {
sscanf(line, "%s %s %s %s %s %s",
crons[i].Minutes,
crons[i].Hours,
crons[i].Days,
crons[i].Months,
crons[i].DayOfWeek,
crons[i].Command);
if (atoi(crons[i].Minutes)<0 || atoi(crons[i].Minutes>59)){
exit(EXIT_FAILURE);
}
printf("Found cron: %s %s %s %s %s %s \n",
crons[i].Minutes,
crons[i].Hours,
crons[i].Days,
crons[i].Months,
crons[i].DayOfWeek,
crons[i].Command);
i ++;
}
}
//printf("Found %d cron jobs", i);
int input = 7;
for (int i =0;i<sizeof(crons)/sizeof(crons[0]);i++){
if (atoi(crons[i].Months))==input{
if (crons[i].Minutes[0] != '*' ){
n1 = atoi(crons[i].Minutes);
}
if (crons[i].Hours[0] != '*' ){
n2 = atoi(crons[i].Hours);
}
int mins = n2*60 + n1;
printf("%d\n",mins);
}
}
fclose(ctf);
return 0;
}Editor is loading...