/* How to execute the program? 1. Compile and create executable gcc -Wall inputgen.c -o inputgen 2. Execute the program with two numbers ./inputgen 20 5 => produce twenty lines, each with 5 words 3. To save the output to a file ./inputgen 20 5 > datafile */ /* ECE 264 Yung-Hsiang Lu, Purdue Spring 2009 */ #include #include #include char * firstNames[] = { "Aaron", "Amy", "Andrew", "Angela", "Anthony", "Ava", "Bill", "Catherine", "Cathy", "Charles", "David", "Donna", "Elizabeth", "Emily", "Ethan", "Gerry", "Isabella", "Jacob", "James", "Jean", "Jennifer", "Jessica", "John", "Karen", "Kathy", "Larry", "Linda", "Lisa", "Mark", "Mary", "Matthew", "Melissa", "Mike", "Nancy", "Paul", "Richard", "Robert", "Sharon", "Sophia", "Stacey", "Susan", "Tina", "Tom" }; char * lastNames [] = { "Anderson", "Baker", "Bell", "Black", "Brown", "Collins", "Cook", "Cox", "Davis", "Gray", "Dyer", "Green", "Harris", "Hill", "Hunt", "Jackson", "Johnson", "Jones", "Kellar", "Lee", "Martin", "Max", "Mitchell", "Miller", "Moore", "Morgon", "Parker", "Poore", "Rowe", "Sharp", "Simpson", "Smith", "Taylor", "Thomas", "Thompson", "Wabash", "Walker", "White", "Wilkers", "Williams", "Wilson", "Woods", "Xu", "Young", "Zachary", "Zheng" }; char * streetNames [] = { "ArmstrongAvenue", "BakerStreet", "CanalStreet", "ClevelandStreet", "DowAvenue", "EastRoad", "FairfaxAvenue", "FirstStreet", "ForestRoad", "GoldenCourt", "HarborAvenue", "HoustonStreet", "LakeviewAvenue", "LexingtonAvenue", "MadisonAvenue", "MainStreet", "MapleStreet", "NorthwesternAvenue", "OakRoad", "ParkRoad", "PineAvenue", "ScottStreet", "SecondStreet", "StevensonStreet", "StocktonStreet", "ThirdStreet", "TimesSquare", "UniversityAvenue", "VictorCourt", "WallStreet", "WashingtonStreet", "WoodsAvenue" }; const int numFirstNames = sizeof(firstNames) / sizeof(char *); const int numLastNames = sizeof(lastNames) / sizeof(char *); const int numStreetNames = sizeof(streetNames) / sizeof(char *); void printAWord() { switch (rand() % 3) { case 0: printf("%s", firstNames[rand() % numFirstNames]); break; case 1: printf("%s", lastNames[rand() % numLastNames]); break; case 2: printf("%s", streetNames[rand() % numStreetNames]); break; default: break; } } int main(int argc, char * argv[]) { int numLine = 0; int lineCnt; int numWord; int wordCnt; /* printf("numFirstNames = %d\n", numFirstNames); printf("numLastNames = %d\n", numLastNames); printf("numStreetNames = %d\n", numStreetNames); */ if (argc < 3) { printf("number of lines and number of word per line\n"); return -1; } numLine = strtol(argv[1], NULL, 10); numWord = strtol(argv[2], NULL, 10); if ((numLine <= 0) || (numWord <= 0)) { printf("must be positive numbers\n"); return -1; } if (numWord > 10) { printf("too many words, do not exceed 10\n"); return -1; } srand (time(NULL)); /* randomize the seed to ensure the list is different in every execution */ for (lineCnt = 0; lineCnt < numLine; lineCnt ++) { /* always add one word */ printAWord(); for (wordCnt = 1; wordCnt < numWord; wordCnt ++) { printf(" "); printAWord(); } printf("\n"); } return 0; }