#include #include #include #include struct LinkedList { int* count; char* data; struct LinkedList *next; }; typedef struct LinkedList *node; int main(int argc, char *argv[]) { int i; FILE *f; char line[30]; const char* pattern = "(.+),.+"; node head = NULL; int linecount; char firstline[30]; regex_t preg; regmatch_t pmatch[50]; regcomp(&preg, pattern, REG_EXTENDED); for (i=1; i 1) { if (!regexec(&preg, line, 3, pmatch, 0)) { if (head == NULL){ head = (node)malloc(sizeof(struct LinkedList)); head->data = malloc(50); head->next = NULL; strncpy(head->data, line + pmatch[1].rm_so, pmatch[1].rm_eo - pmatch[1].rm_so); head->count = (int*)calloc(argc-1, sizeof(int)); head->count[i-1]++; } else { node temp, p; p = head; temp = (node)malloc(sizeof(struct LinkedList)); temp->data = malloc(50); temp->next = NULL; temp->count = (int*)calloc(argc-1, sizeof(int)); temp->count[i-1] = 1; strncpy(temp->data, line + pmatch[1].rm_so, pmatch[1].rm_eo - pmatch[1].rm_so); while(1){ int res = strcmp(temp->data, p->data); if (res==0) { p->count[i-1]++; break; } else { if (p->next == NULL) { p->next = temp; break; } } p = p->next; } } } } else { regexec(&preg, line, 3, pmatch, 0); strncpy(firstline, line + pmatch[1].rm_so, pmatch[1].rm_eo - pmatch[1].rm_so); } } fclose(f); } node ptr = head; printf("%s", firstline); for (i=1; idata); int j; for (j=0; jcount[j]); printf("\n"); ptr = ptr->next; } }