we’re going to need to open contains the pin name. Again we use snprintf to build str_direction_file . Note as well, that to avoid a magic number we’ve also defined a maximum length. ... char str_direction_file[MAXSTR]; snprintf(str_direction_file, (MAXSTR*sizeof(char)), "/sys/class/gpio/gpio%d/direction", pin); if ((sysfs_handle = fopen(str_direction_file, "w")) == NULL) { printf("ERROR: Cannot open direction