// genList.c // by // K. J. Rock // November 15, 2018 // for Bacona Design #include #include #include #include // Create a generic field so you can store and retrieve heterogeneous lists // each list has a head which describes how many fields, their types, // and names in pairs and the value or string struct genField { char *type; // field type char *name; // field name union data // field data { int a; double b; char *p; } data; } ; struct genField gField[20]; // what is a good maximum # of fields? // I think this all should be part of the list class // This would give it the tightest linkage // you really want to be able to use these functions // inside of your list functions. // Make life easier and put them into the same class // A list is made of a number of records // each records has fields of data // each field has a name, a type, and its data // So when you call up myList = new List(); // you get all the parts to create each field in each record // and then make the list out of many of those records. // The database tools will add, delete, edit, save/read, write report lists from queries // And hopefully due to this work on a generic list header // you will be able to open multiple lists // and create reports from complex queries on them all // Cool :) int makeField(char *name, char type, union data); // now define makeField() // and create a UI to wrap around it. // Have it build as many fields as you want. // need to create fields // save fields // read fields // and edit fields // anything else? int main(void) { int i, len; char *name, *r, *s, *t; name = (char *) malloc(sizeof(char) * 10); strcat(name, "Theobald\0"); r = (char *) malloc(sizeof(char) * 6); strcat(r, "Years\0"); s = (char *) malloc(sizeof(char) * 6); strcat(s, "Name\0"); t = (char *) malloc(sizeof(char) * 3); strcat(t, "Pi\0"); gField[0].data.a = 3; gField[1].data.b = 3.1415926535; gField[0].type = (char *) malloc(sizeof(char)); *gField[0].type = 'i'; gField[1].type = (char *) malloc(sizeof(char)); *gField[1].type = 'd'; gField[2].type = (char *) malloc(sizeof(char)); *gField[2].type = 's'; len = strlen(r); gField[0].name = (char *) malloc(sizeof(char) * len); gField[0].name = r; len = strlen(t); gField[1].name = (char *) malloc(sizeof(char) * len); gField[1].name = t; len = strlen(name); gField[2].data.p = (char *) malloc(sizeof(char) * len); gField[2].data.p = name; gField[2].name = s; printf("\n\n"); printf("%d, %f, %s \n", gField[0].data.a, gField[1].data.b, gField[2].data.p); // printf("%s, %s \n", gField[0].name, gField[2].data.p); printf("\n\n"); // printf("field type = %c\n", *gField[0].type); // dereference here // printf("field name %s \n\n", gField[0].name); for (i=0; i<3; i++) { printf("Field #%d --> ", i); printf("Name => %s \t", gField[i].name); printf("Type => %c \t", *gField[i].type); printf("Value => "); if (*gField[i].type == 'i') printf("integer %d \n", gField[i].data.a); else if (*gField[i].type == 'd') printf("double %f \n", gField[i].data.b); else if (*gField[i].type == 's') printf("string %s \n", gField[i].data.p); } printf("\n\n"); return 0; } ///////////////////////////////////////////////// /* char src[50], dest[50]; strcpy(src, "This is source "); strcpy(dest, "This is the destination "); //strcat(dest, src); //printf("\n\nFinal destination string : %s \n", dest); */