Hi walter,
On Sun, Mar 16, 2014 at 9:54 AM, walter harms <wha...@bfs.de> wrote: > Am 16.03.2014 16:52, schrieb milkyway: > > Hi, I am new to this group. Following is a code I tried from Derek Malloy's > > videos, to read the gpio pin values. When I run this program I get > > "Segmentation fault". I can't make out how it happens. Can anybody help me > > out? ...snip... > > int readButton(int pin) > > { > > char setValue[4], GPIOPin[4], GPIODirection[MAX], GPIOValue[MAX]; > > FILE *GPIOHandler; > > int i; > > sprintf(GPIOPin, "%d", pin); > > sprintf(GPIODirection, "/sys/class/gpio/gpio%s/direction", GPIOPin); > > sprintf(GPIOValue, "/sys/class/gpio/gpio%s/value", GPIOPin); > > if ((GPIOHandler = fopen("/sys/class/gpio/export", "ab")) == NULL) > > { > > fprintf(stderr, "Failed to export the GPIO\n"); > > return 1; > > } > > strcpy(setValue, GPIOPin); > > fwrite(GPIOPin, sizeof(char), 2, GPIOHandler); > > anything bad with > fprintf(GPIOHandler,"%d",pin) ? That would probably be better in this situation (less buffer manipulation, and fprintf to a file won't cause any buffer overruns). Similarly for writing out the direction below. -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.