LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   reading /proc throught C code (https://www.linuxquestions.org/questions/programming-9/reading-proc-throught-c-code-484310/)

knobby67 09-17-2006 06:27 AM

reading /proc throught C code
 
Hello, I'm hoping someone can help me out on this problem. I'm trying to read an entery from the proc system using C. Basically I'm using an io board which detects a switch. I can read at command promp using cat /proc/ioboard/input_1 which returns either a 1 or 0 depending on the status of the input. I've tried to read in throught c (the lang I'm coding in) using a simple
/***********code example******************/
input = open("/proc/ioboard/input_1",O_RDONLY);
printf("\n input = %d",input);
/*****************************************/

However this returns 3 no matter what the input, I assume I can't just read from /proc? Can anyone advise what I need to do. Thanks

jim mcnamara 09-17-2006 06:59 AM

Code:

#include <stdio.h>
int foo(void)
{
 char buf[32]={0x0};
 int value=0;
 FILE *fd=fopen("/proc/ioboard/input_1","r");
 fgets(buf,32,fd);
 value=atoi(buf);
 printf("\n input = %d\n",value);
 fclose(fd);
 return value;
}


knobby67 09-17-2006 07:16 AM

thanks, just realised I forgot to read :cry: Sorry for the stupidity!


All times are GMT -5. The time now is 10:20 PM.