I always seem to write code in C that is mostly object oriented, so say I had a source file or something I would create a struct then pass the pointer to this struct to functions (methods) owned by this structure:struct foo {    int x;};struct foo* createFoo(); // mallocs foovoid destroyFoo(struct foo* foo); // frees foo and its thingsIs this bad practice? How do I learn to write C the proper way.
Is it bad to write object oriented C?
c
No, this is not bad practice, it is even encouraged to do so, although one could even use conventions like struct foo *foo_new(); and void foo_free(struct foo *foo);Of course, as a comment says, only do this where appropriate. There is no sense in using a constructor for an int. The prefix foo_ is a convention followed by a lot of libraries, because it guards against clashing with naming of other libraries. Other functions often have the convention to use foo_<function>(struct foo *foo, <parameters>);. This allows your struct foo to be an opaque type.Have a look at the libcurl documentation for the convention, especially with subnamespaces, so that calling a function curl_multi_* looks wrong at first sight when the first parameter was returned by curl_easy_init().There are even more generic approaches, see Object-Oriented Programming With ANSI-C