Posts

Showing posts from August, 2023

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; }