LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2006, 06:27 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
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

Last edited by knobby67; 09-17-2006 at 06:30 AM.
 
Old 09-17-2006, 06:59 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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;
}
 
Old 09-17-2006, 07:16 AM   #3
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
thanks, just realised I forgot to read Sorry for the stupidity!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading /proc/<pid>/mem magnus.therning Programming 2 07-16-2006 08:29 AM
reading /proc file in kernel help needed arunka Programming 2 03-17-2005 05:51 AM
Reading from a /proc file russelh Programming 2 12-02-2004 05:30 PM
Dbx stack dump for a C/Proc Code. Help! nathan75 Programming 0 10-13-2004 08:48 AM
api for reading files under /proc sreddy Programming 2 09-01-2004 02:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration