1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <string.h>
#include "test.h"
struct MyStruct {
void (*myFunc)(void *, const void *, size_t);
};
// Initialize the struct with memcpy assigned to the function pointer
struct MyStruct myStruct = {
.myFunc = memcpy
};
int main() {
// Use the function pointer
char src[20] = "Hello, World!";
char dest[20];
myStruct.myFunc(dest, src, strlen(src) + 1);
printf("Copied string: %s\n", dest); // Should print: "Copied string: Hello, World!"
ASSERT(13, strlen(dest));
return 0;
}
|