Callback functon - Fixed
I just love people who make the effort and help to teach others new stuff. But with code samples i don't understand why you don't test the code before publishing. I found an interesting example off callback function example but it was not working. Here is the proper stuff:)
Original
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct
- {
- int age;
- char name[10];
- char surname[10];
- }person;
- // Simple fuction to be called as callback
- void callMe(person *m)
- {
- }
- int main(int argc, char *argv[])
- {
- // Declaration of pointer to function with same signiture as callMe
- void (*callback)(person*)
- ;
- // Create struct and fill with data
- person s;
- s.age = 27;
- //Don't forget how to copy strings in C/C++
- strcpy(s.name, "Dejan");
- strcpy(s.surname, "Cencelj");
- // Init
- callback = (void*)callMe;
- // Call to callMe with callback
- callback(&s);
- system("PAUSE");
- return 0;
- }
Comments
Post a Comment