Posts

Featured Post

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       

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:     

Todo List in C without file I/O and DMA.

 Main.c #include<stdio.h> #include<stdbool.h> #include<string.h> #define MAX_NAME 25 #define MAX_TASKS 50 typedef struct task{     char name[MAX_NAME];     short int Status; }task; void addTask(task* tasks,int* totalTasks); void removeTask(int* totalTasks,task* tasks); void viewTask(int* totalTasks,task* tasks); int main(){     task tasks[MAX_TASKS];     int totalTasks = 0;     int input;     while(1){                 printf("Welcome to Todo-List Manager\n");         printf("Enter the corresponding number to the task you want to do\n");         printf("1.Add a new task\n");         printf("2.View all your tasks\n");         printf("3.Remove a task\n");         printf("4.Exit the program\n");         scanf("%d",&input);                 switch(input){             case 1:                 addTask(tasks,&totalTasks);                 break;             case 2:                 viewTask(&totalTa

Command Line Calculator in C.

 A simple Command Line Calculator in C. Main.c #include<stdio.h> #include<stdlib.h> #define LESS_ARGS "Insufficient arguments\n" #define USAGE "Usage : calc <option> <arguments>\n" void add(char* argv[],int argc); void subtract(char* argv[],int argc); void multiply(char* argv[],int argc); int main(int argc, char* argv[]){     if (argc < 2){         printf(USAGE);         return 1;     }     else{        switch(*argv[1]){         case 'a':             add(argv,argc);             break;         case 's':             subtract(argv,argc);             break;         case 'm':             multiply(argv,argc);             break;         default:             printf(USAGE);        }     }     return 0; } void add(char* argv[],int argc){     if(argc < 4){         printf(LESS_ARGS);         return;     }         else{         int temp = 0;         for(int i = 2;i < argc;i++){             printf("DEBUG[ADD FOR LOOP]

Star Pyramid in C

 This is a basic program for star pyramid in C programming language #include<stdio.h> #include<stdlib.h> #define USAGE "Usage : pyramid <rows>\n" int main(int argc, char **argv){     if (argc < 2){         printf(USAGE);         return 1;     }     int maxStars = (atoi(argv[1]) *2) -1;     for (int i =1;i <= (atoi(argv[1])*2) - 1 ;i+=2){         int spaces = (maxStars - i)/2;         for(int j =0;j < spaces;j++){             printf(" ");         }         for(int k = 1;k<= i;k++){             printf("*");         }         for(int l = 0;l < spaces;l++){             printf(" ");         }         printf("\n");             }     return 0; }