I am currently trying to make my code safer and more structured. So far, when I want to read an analog input value, I use the following function which works fine:
FILE *fp = popen("cat /sys/bus/iio/devices/iio\\:device0/in_value_raw", "r");
char *ln = NULL;
size_t len = 0;
while (getline(&ln, &len, fp) != -1)
fputs(ln, stdout);
free(ln);
pclose(fp);
int result = atoi(ln);
However, so far, I do not have the means to get error messages or check if the value has been read correctly... Is there a way to change that? I have looked at some articles about "pipe streaming", but since they are always about executing files, I do not know, if I am on the right path...
If you could tell me, how to best approach that problem it would be of great help.
Thank you for your time!