/** * A Little program to print the contents of an array * * @author gtowell * Created: April 16, 2021 * **/ #include #include #include #ifndef NULL #define NULL (void *)0 #endif /** * A ridiculously complex way to print an array, but almost * generic and, even better, it follows qsort * @param base -- a pointer to the start of the array -- or at * least the start of the portion of the array to be printed * @param nmemb -- the number of item in the array (or at least * the number of items to be printed) * @param size -- the number of bytes of the items in the array * @param fmt -- a formatting string * **/ void parray2(void * base, size_t nmemb, size_t size, char* fmt) { for (int i = 0; i < nmemb; i++) { char c = *((char *)base); printf(fmt, c); base += size; } printf("\n"); } int main(int argc, char const *argv[]) { srand(time(NULL)); char aa[100]; for (int i = 0; i < 100; i++) aa[i] = 'a' + (rand() % 26); parray2(aa, 100, sizeof(char), "%c"); }