#include "clio.h" /* * File: * silly.c * Summary: * Experiments with function pointers, reading, and writing them. */ /********************************************************************* * Wicked-Sweet Helper Functions * *********************************/ /* * Given the name of a standard "continuous" function as a string, * return that function. * Returns NULL if the name is not known. Clever programmers * check the return value. */ continuous getContinuousFunction(char *name1) { fprintf(stderr, "getCont: %s\n", name1); if (0 == strcasecmp(name1, "Time Spent")) { return getLengthC; } else if (0 == strcasecmp(name1, "Time Accessed")) { return getStartC; } else if (0 == strcasecmp(name1, "URL")){ return getPageC; } else if (0 == strcasecmp(name1, "Category")){ return getTypeC; } else if (0 == strcasecmp(name1, "Windows")){ return getUWSC; } else { return NULL; } } /* getContinuousFunction */ /* * Given one of the standard "continuous" function, return the name * of that function. */ char * getContinuousName(continuous c) { if (c == getLengthC) { return "getLength"; } else if (c == getStartC) { return "getStart"; } else if (c == getTypeC) { return "getType"; } else if (c == getPageC){ return "getPage"; } else if (c == getUWSC){ return "getUWS"; } else { return "getSomething"; } } // getContinuousName(continuous c) /********************************************************************* * Main * ********/ main() { char funcName[128]; getX = getLengthC; getY = getStartC; printf("getX:%s\n", getContinuousName(getX)); printf("getY:%s\n", getContinuousName(getY)); printf("Please enter a function name: "); scanf("%s",funcName); getZ = getContinuousFunction(funcName); printf("getZ:%s\n", getContinuousName(getZ)); exit(0); } /* main() */