//* passing a structure as a generic pointer, structures in memory *

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> struct myDataType { char myString[11]; // up to 10 characters // 11 bytes unsigned short int myNumber; // 0..65535 // 2 bytes unsigned char myByte; // 1 byte }; // total: 14 bytes?? void print_bytes(char* buffer, unsigned char length) { // ^^^^^^ so this is not a universal pointer unsigned char i; for (i = 0; i < length; ++i) fprintf(stdout, " %u", (unsigned char)buffer[i]); fprintf(stdout, "\n"); } void main() { struct myDataType myVariable; // ^^^^^^ since print_bytes does not accept an universal pointer // we have to declare the variable in compatible memory space myVariable.myNumber = 12345; myVariable.myByte = 234; fprintf(stdout, "Please enter up to 10 characters of text. "); fscanf(stdin, "%10s", myVariable.myString); // ^^^^ size specification here prevents buffer overrun // but don;t count that every embedded system library will also do that for you fprintf(stdout, "The size of the structure is %ld bytes. The contents are:\n", sizeof(myVariable)); print_bytes((char*)&myVariable, sizeof(myVariable)); // ^^^^^^^ typecast to a more generic pointer // to a sequence of bytes. // actualy (void*) would be even better }