Time Calculator/src/main.c (Time Calculator)
//This is the main script which will handle user input and call the associated "It" function
//The "It" function is described in the timec.h header file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "timec.h"
#include "timef.h"
//For the detail and usage of the functions go to the associated header f
//An enumerator for the options
enum options{
calculate = 'c',
add = 'a',
sub = 's',
help = 'h',
file = 'f'
};
int main(int argc,char **argv)
{
if(argc < 2){
printf(USAGE);
return 1;
}
if(argv[1][0] != '-'){
printf("Usage : \n");
printf(USAGE);
return 1;
} else {
//code var is used to store the int returned by a "It" function
//and is used as the return code for the program
int code;
switch(argv[1][1]){
case calculate:
code = calculateIt(argc,argv);
return code;
case add:
code = addIt(argc,argv);
return code;
case sub:
code = subIt(argc,argv);
return code;
case help:
helpIt();
return 1;
case file:
code = fileIt(argc,argv);
return code;
default:
printf(INVALID_OPTION);
return 1;
}
}
}
//The "It" function is described in the timec.h header file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "timec.h"
#include "timef.h"
//For the detail and usage of the functions go to the associated header f
//An enumerator for the options
enum options{
calculate = 'c',
add = 'a',
sub = 's',
help = 'h',
file = 'f'
};
int main(int argc,char **argv)
{
if(argc < 2){
printf(USAGE);
return 1;
}
if(argv[1][0] != '-'){
printf("Usage : \n");
printf(USAGE);
return 1;
} else {
//code var is used to store the int returned by a "It" function
//and is used as the return code for the program
int code;
switch(argv[1][1]){
case calculate:
code = calculateIt(argc,argv);
return code;
case add:
code = addIt(argc,argv);
return code;
case sub:
code = subIt(argc,argv);
return code;
case help:
helpIt();
return 1;
case file:
code = fileIt(argc,argv);
return code;
default:
printf(INVALID_OPTION);
return 1;
}
}
}
Comments
Post a Comment