I am currently working on a project that requires me to call a Linux command during a C code. I have found on other sources that I can do this using the system() command and then save the value for the Linux shell to my C program.
For example, I will need to change the directory to
root:/sys/bus/iio/devices/iio:device1>
and then input
cat in_voltage0_hardwaregain
as the command. This should output a double into the C.
So my sample code would be:
#include <stdio.h>
#include <stdlib.h>
double main() {
char directory[] = "cd /sys/bus/iio/devices/iio:device1>";
char command[] = "cat in_voltage0_hardwaregain";
double output;
system(directory);
output = system(command);
return (0);
}
I know this probably not the best way to do this, so any information is greatly appreciated.