Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <malloc.h>
- #include <string.h>
- struct node {
- struct node *next;
- char name[30];
- char brand[5];
- char type[20];
- char damage[20];
- struct node *prev;
- };
- void clrscr() {
- system("@cls||clear");
- }
- struct node *start = NULL;
- struct node *create_ll(struct node *);
- struct node *display(struct node *);
- struct node *insert_end(struct node *);
- struct node *delete_beg(struct node *);
- int main(int argc, char *argv[]) {
- int choice;
- do {
- clrscr();
- printf("PRINTER SERVICES\n");
- printf("++++++++++++++++++++++\n\n");
- printf("1. Service List\n");
- printf("2. Add Service\n");
- printf("3. Take Service\n");
- printf("4. Exit\n\n");
- printf("> Please input your choice : ");
- scanf("%d", &choice);
- switch(choice) {
- case 1: {
- start = display(start);
- getch();
- break;
- }
- break;
- case 2: {
- start = create_ll(start);
- getch();
- break;
- }
- break;
- case 3: {
- start = delete_beg(start);
- getch();
- break;
- }
- case 4: break;
- }
- } while(choice !=5);
- getch();
- return 0;
- }
- struct node *create_ll(struct node *start) {
- struct node *new_node, *ptr;
- char name[25],brand[5],type[20],damage[20];
- int b=0;
- printf("\nInput Customer Name : ");
- fflush(stdin);
- scanf("%[^\n]",&name);
- do{
- printf("Input Printer's Brand [canon/epson/hp] : ");
- scanf("%s",&brand);
- if (strcmp("canon",brand)==0) {
- b=1;
- }
- else if (strcmp("epson",brand)==0) {
- b=1;
- }
- else if (strcmp("hp",brand)==0) {
- b=1;
- }
- else {
- b=0;
- }
- } while (b==0);
- do {
- printf("Input Printer's Type [4...20]: ");
- scanf("%s",&type);
- } while (strlen(type)<4 || strlen(type)>20);
- do {
- printf("Input Damaged [5...20]: ");
- fflush(stdin);
- scanf("%[^\n]",&damage);
- } while (strlen(damage)<5 || strlen(damage)>20);
- new_node = (struct node*)malloc(sizeof(struct node));
- strcpy(new_node->name,name);
- strcpy(new_node->brand,brand);
- strcpy(new_node->type,type);
- strcpy(new_node->damage,damage);
- if(start == NULL) {
- new_node->next = NULL;
- start = new_node;
- }
- else {
- ptr=start;
- while(ptr->next!=NULL) {
- ptr=ptr->next;
- }
- ptr->next = new_node;
- new_node->next=NULL;
- }
- return start;
- }
- struct node *display(struct node *start) {
- int no=1;
- struct node *ptr;
- ptr=start;
- clrscr();
- printf("\nP R I N T E R S E R V I C E S\n===============================\n\n");
- printf("---------------------------------------------------------------------------------------------------------\n");
- printf("| No. | name \t\t|Printer's Brand | Type | \t Damaged |\n");
- printf("---------------------------------------------------------------------------------------------------------\n");
- while (ptr!=NULL) {
- printf("|");
- printf("%-6d |",no);
- printf("%-30s |",ptr->name);
- printf("%-18s |",ptr->brand);
- printf("%-20s |",ptr->type);
- printf("%-20s |\n",ptr->damage);
- ptr=ptr->next;
- no++;
- }
- return start;
- }
- struct node *delete_beg(struct node *start) {
- struct node *ptr;
- ptr = start;
- start = start -> next;
- start -> prev = NULL;
- free(ptr);
- return start;
- }
Advertisement
Add Comment
Please, Sign In to add comment