Posts

Showing posts from January, 2024

Time Calculator/src/timef.h (Time Calculator)

//This file contains function declaration and implementations for all file related functions like //opening file and parsing from file and fsize() that returns file size #include <stdlib.h> #include <stdio.h> #include <string.h> #define ERR_FILE_NOT_FOUND "The specified file is not found, please recheck the file name and path\n" #define ERR_CODE_FILE_NOT_FOUND 40 #define MAX_USERS_BYTE 251 typedef struct {     char id[26];     Time time; }User; int totalLines(FILE* file); int len(char* str); long fsize(FILE* file); char* removeSpaces(char* str,int length); int fileIt(int argc,char** argv); char* loadLine(FILE* file,int n); int countChars(char* str,char c); int totalUsers(FILE* file); User** parseUsers(FILE* file,int n); void parseUserTime(char* line,User** users,int totalUsers); void calcUserTime(FILE* file,User** users); int removeColon(char* str,int len); int len(char* str){     int counter = 0;     short ended = 0;     while(ended == 0){         if (str[c

Time Calculator/src/timec.h (Time Calculator)

//This file contains function declarations and implementations for all non-file handling related functions //used by main.c #define USAGE "timec [OPTION] [ARGUMENT]... (The time is entered in 24-hour clock)\n" #define INVALID_OPTION "The option you provided is invalid, type \"timec -h\" for help\n" #define TIME_LENGTH 6 #define HELP "Enter \"typec -h\" for help\n" typedef struct {     int hour;     int minute; } Time; //parseTime() function is used to parse time from a string and put the parsed hour and minute //into the members of the provided Time struct using its pointer void    parseTime(char* str,Time* time); //putTime function is used to convert Time struc into a string void    putTime(char* str,Time* time); //calcDiffH() is used to calculate the difference between two given hours int     calcDiffH(Time* start,Time* end); //calcDiffM() is used to calculate the difference between two given minutes int     calcDiffM(Time* start,Time

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:     

Time Calculator

 This is a time calculator made in C which is used to calculate, add or subtract time. It currently supports only 24-hour clock and the support for 12-hour and time calculations from file are planned but depends if I stay invested in this little project.  the file structure of this program : Time Calculator/src/     main.c # this is the main C file     timec.h # this contains the definitions and implementations of the functions used in main.c     timef.h # this files contains the functions used for operation on file  Total lines of code :              -- -------------------------------------------------------------------------------------------------                Language                     files          blank        comment           code              - --------------------------------------------------------------------------------------------------                C/C++ Header                     2             41             24                      334                C