📄 ticket.c.svn-base
字号:
/* ticket.c */#define _XOPEN_SOURCE#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include "ticket.h"ticket_collection_t *ticket_collection_open(const char *path){ FILE *fp = NULL; ticket_collection_t *col; ticket_t * tics; char buffer[512]; int count = 0; if((fp = fopen(path, "r"))== NULL ){ return NULL; } if(fgets(buffer, 512, fp) == NULL)return NULL; count = atoi(buffer); if(count<=0) return NULL; if((col = (ticket_collection_t *)malloc(sizeof(ticket_collection_t))) == NULL){ fclose(fp); return NULL; } col->len = 0; if((tics = (ticket_t *)malloc(sizeof(ticket_t)*count)) == NULL){ fclose(fp); return NULL; } col->tickets = tics; while(fgets(buffer,512, fp) != NULL){ char *id; char *trainno; char *time; char *num; char *des; struct tm tim; id = buffer; if((trainno = strstr(id,"\t")) != NULL){ printf("."); *trainno = '\0'; trainno += 1; }else continue; if((time = strstr(trainno,"\t")) != NULL){ *time = '\0'; time += 1; }else continue; if((num = strstr(time,"\t")) != NULL){ *num = '\0'; num += 1; }else continue; if((des = strstr(num,"\t")) != NULL){ *des = '\0'; des += 1; }else continue; des[strlen(des)-1] = '\0'; col->tickets[col->len].id = atoi(id); strcpy(col->tickets[col->len].trainno,trainno); strptime(time,"%Y-%m-%d %H:%M:%S",&tim); col->tickets[col->len].time = mktime(&tim); col->tickets[col->len].num = atoi(num); strcpy(col->tickets[col->len].description,des); col->len ++; if(col->len >= count)break; } return col;}int ticket_collection_close(ticket_collection_t * tc){ free(tc->tickets); free(tc); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -