int main(int argc, char **argv) { FILE *fp; char str[MaxLineSize+1]; char str1[MaxLineSize+1] = "", str2[MaxLineSize+1] = ""; int count; if(argc < 3) { PrintUsage(); return 1; } if( !IsSorted(argv[1], (atoi(argv[2])-1), 'S') ) { SortTable(argv[1], atoi(argv[2]), 'S', "CountName.temp"); if( ( fp = fopen("CountName.temp", "r") ) == NULL ) { ErrMsg("Error: fopen failed.\n"); return false; } } else if( ( fp = fopen(argv[1], "r") ) == NULL ) { ErrMsg("Error: fopen failed.\n"); return false; } count = 1; for( TableRow theRow; theRow.Get(fp); ) { ColCpy( str2, theRow.Column(atoi(argv[2])-1) ); if( strcmp(str2, "") == 0 ) continue; if( strcmp(str1, str2) == 0 ) count++; else if( strcmp(str1, "") != 0 ) { printf("%s\t%d\n", str1, count ); count = 1; } strcpy( str1, str2 ); } if( strcmp(str1, "") != 0 ) printf("%s\t%d\n", str1, count ); fclose(fp); remove("CountName.temp"); return 0; }
int main(int argc, char **argv) { Str2BoolMap theMap; char str[MaxLineSize+1]; if(argc != 4) { PrintUsage(); return 1; } theMap.AddIntoMap( argv[2], atoi(argv[3])-1 ); for( TableRow theRow; theRow.Get(); ) { ColCpy( str, theRow.Column(atoi(argv[1])-1) ); if( theMap.IsInMap(str) == true ) theRow.Print(); } return 0; }
int main(int argc, char **argv) { Str2StrMap theMap; char str[MaxLineSize+1]; char buf[MaxLineSize+1]; char *token = NULL; if(argc < 5 || argc > 6) { PrintUsage(); return 1; } theMap.AddIntoMap( argv[2], atoi(argv[3])-1, atoi(argv[4])-1); for( TableRow theRow; theRow.Get(); ) { ColCpy( str, theRow.Column(atoi(argv[1])-1) ); token = strtok( str, ",; " ); while(token != NULL) { theMap.At(token, buf); if( buf[0] != '\0' ) { theRow.PrintWithoutNewline(); printf("\t%s\n", buf); break; } else if( argc == 6 ) { theRow.PrintWithoutNewline(); printf("\t%s\n", argv[5]); } token = strtok(NULL, ",; "); } token = NULL; } return 0; }