main.c

来自「This is a safe double linked list data s」· C语言 代码 · 共 98 行

C
98
字号
#include <stdio.h>#include <stdlib.h>#include "circular_dlist.h"#define LINE_LENGTH 64int m;int main(int argc, char** argv){    FILE *fp = NULL;    char line[LINE_LENGTH], event;    int id, type;    CreateNew_dl(-1,5);    /* Check command line arguments */    if( argc < 3 )    {        printf("\n Usage: %s <m> <input-file>\n", argv[0]);        return(EXIT_FAILURE);    }    /* Read the m parameter */    m = atoi(argv[1]);    /* Open input file */    if( ( fp = fopen(argv[2], "r") ) == NULL )    {        printf("\n Could not open file: %s\n", argv[2]);        return(EXIT_FAILURE);    }    /* Read input file line-by-line and handle the events */    while( fgets(line, LINE_LENGTH, fp) != NULL )    {        /* Uncomment the line below when in debug mode */        /* printf("\n Event: %s ", line); */        switch(line[0])        {            /* Join event */            case 'J':                sscanf(line, "%c %d", &event, &id);                /* id: the id of the node to be inserted */                Insert_dl(id);                /* your code... */                break;            /* Leave event */            case 'L':                sscanf(line, "%c %d", &event, &id);                /* id: the id of the node to be deleted  */		Delete_dl(id);                /* your code... */                break;            /* Insert event */            case 'I':                sscanf(line, "%c %d %d", &event, &id, &type);                /* id: the id of the file, type: the type of the file to be inserted */		Insert_File(id,type);                /* your code... */                break;            /* Delete event */            case 'D':                sscanf(line, "%c %d", &event, &id);                /* id: the id of the file, to be deleted */		Delete_File(id);                /* your code... */                break;            /* Find event */            case 'F':                sscanf(line, "%c %d", &event, &id);                /* id: the id of the file, to be searched for */		Find_File(id);                /* your code... */                break;            /* Print event */            case 'P':                sscanf(line, "%c", &event);		print_dl();                /* your code... */                break;            /* Ignore everything else */            default:                /* Uncomment the line below when in debug mode *///                 printf("\n Ignoring line: %s", line);                break;        }    }    return (EXIT_SUCCESS);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?