rouch_neck:
But strangely my YUN board does not have /sys/class/gpio/gpio18
As sonnyyu is demonstrating, the first line of code you listed (echo 18 > /sys/class/gpio/export) creates the /sys/class/gpio/gpio18 device.
You can do it all in C, but that means opening up a bunch of different devices (export, gpio18/direction, etc.) Since all of those commands are already in an existing script file, it's probably easiest to just invoke that script file rather than try to translate it all into C. For example: