remove bug with strings

This commit is contained in:
Siegfried Kienzle
2017-03-24 17:03:46 +01:00
parent b15d09216e
commit a2baf654b6

View File

@@ -1,18 +1,18 @@
/* /*
* switch.c * switch.c
* How to register an button and count this * How to register an button and count this
* author: Simon Wörner, Manuel Vögele, * author: Simon Wörner, Manuel Vögele,
* Siegfried Kienzle * Siegfried Kienzle
* 24-March-2017 * 24-March-2017
* *
* */ * */
#define PIN01 ((char *) "1\n") #define PIN01 "1\n"
#define PIN12 ((char *) "12\n") #define PIN12 "12\n"
#define PIN11 ((char *) "11\n") #define PIN11 "11\n"
#define PIN06 ((char *) "6\n") #define PIN06 "6\n"
#define IN ((char *)"in\n") #define IN "in\n"
#define OUT ((char *)"out\n") #define OUT "out\n"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -24,15 +24,13 @@ int reserve(char* gpioPort)
{ {
int fd; int fd;
char buffer[2]; char buffer[2];
printf("%s", gpioPort);
strcpy(buffer, gpioPort ); strcpy(buffer, gpioPort );
if((fd=open("/sys/class/gpio/export", O_RDWR | O_CREAT | O_TRUNC)) == -1) {
if((fd=open("/sys/class/gpio/export", O_RDWR | O_CREAT | O_TRUNC) == -1)) {
perror(NULL); perror(NULL);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(write(fd, &buffer, sizeof(buffer)) == -1) { if((write(fd, &buffer, sizeof(buffer))) == -1) {
perror("Cannot write into file"); perror("Cannot write into file");
return EXIT_FAILURE; return EXIT_FAILURE;
} }