Hi all, I'm trying to read a misc device /dev/pi
When I do "cat /dev/pi" I get my desired output. However, I'm trying to test with the following code and running into problems.
Seems to open the file successfully but it doesn't read the file correctly. This is the output:Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
char buffer[10];
int main()
{
int test = open("/dev/pi", O_RDWR);
if (test < 0)
printf ("Couldn't open file\n");
else
printf("File Opened Successfully\n");
int test2 = read(test,*buffer,sizeof(buffer));
printf("The fd is: %i\n", test);
printf("Output from read function: %i\n", test2);
printf("Pi: %s", buffer);
}
File Opened Successfully
The fd is: 3
Output from read function: -1
Pi:
Any help?