sparkfun / pcDuino

Example code for use on the pcDuino
https://www.sparkfun.com/products/11712
Other
39 stars 27 forks source link

Fixed bug in writeFile() at gpio_test.cpp, which prevented the data to be written to the file #5

Closed carlosgvaso closed 8 years ago

carlosgvaso commented 8 years ago

The writeFile() function in gpio_test.cpp has a bug which prevents the program to write the data to the gpio file. In line 107 the sprintf() function writes out chars (%c), but it should write ints (%d). This is the way that is done by the pcDuino people in their c_environment library. Here is the fixed writeFile():

103 void writeFile(int fileID, int value)
104 {
105     char buffer[4];  // A place to build our four-byte string.
106     memset((void *)buffer, 0, sizeof(buffer)); // clear the buffer out.
107     sprintf(buffer, "%d", value);
108     lseek(fileID, 0, SEEK_SET);   // Make sure we're at the top of the file!
109     write(fileID, buffer, sizeof(buffer));
110 }