I have a doubt coding in C++

I have a code that I have developed but I don’t know it works, please help me, this code control four relay’s to control two motor stepper using four GPIO’s pin’s, if I messed up please correct me, another doubt when i build in linux terminal with sudo su or sudo and try execute this code, appears a message " no permission " ( using code block build and execute ).

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#define SW_DIR_PATH      "/sys/class/gpio/gpio248/direction"
 
int configure_pins();
int pinunexport();
int iniciar0();
int iniciar1();
void close_fd(int);
int ok;
 
int main(int argc, char *argv[]){
    int fd;
    configure_pins();
    printf("Pinos configurados como Saida\n");
    iniciar0();
    usleep(10000);
 
    do{
 
      iniciar1();
 
        }while(ok = 1);
 
        if (ok = 0){
 
        pinunexport();
        printf("Pinos configurados como inutilizavél no momento, encerrar programa\n");
        return EXIT_FAILURE;
}
        ok = 0;
        return EXIT_SUCCESS;
    }
 
 
 
int configure_pins(){
    int fd;
    int ok;
 
    fd = open("/sys/class/gpio/export", O_WRONLY);
    write(fd, "250", 3);
    close(fd);
 
    fd = open("/sys/class/gpio/gpio250/direction", O_WRONLY);
    write(fd, "out", 3);
    close(fd);
 
    fd = open("/sys/class/gpio/export", O_WRONLY);
    write(fd, "248", 3);
    close(fd);
 
    fd = open("/sys/class/gpio/gpio248/direction", O_WRONLY);
    write(fd, "out", 3);
    close(fd);
 
    fd = open("/sys/class/gpio/export", O_WRONLY);
    write(fd, "173", 3);
    close(fd);
 
    fd = open("/sys/class/gpio/gpio173/direction", O_WRONLY);
    write(fd, "out", 3);
    close(fd);
 
    fd = open("/sys/class/gpio/export", O_WRONLY);
    write(fd, "172", 3);
    close(fd);
 
    fd = open("/sys/class/gpio/gpio172/direction", O_WRONLY);
    write(fd, "out", 3);
    close(fd);
 
    ok = 1;
 
    return EXIT_SUCCESS;
 
}
 
int pinunexport(){
int fd;
   if(fd = open(SW_DIR_PATH, O_WRONLY) <=0){
        perror("Não é possível abrir o arquivo de direção para o PIN \n");
        ok = 0;
        return EXIT_FAILURE;
    }
 
        else {
fd = open("/sys/class/gpio/unexport", O_WRONLY);
    write(fd, "250", 3);
    close(fd);
 
fd = open("/sys/class/gpio/unexport", O_WRONLY);
    write(fd, "248", 3);
    close(fd);
 
fd = open("/sys/class/gpio/unexport", O_WRONLY);
    write(fd, "173", 3);
    close(fd);
 
fd = open("/sys/class/gpio/unexport", O_WRONLY);
    write(fd, "172", 3);
    close(fd);
  }
    return 0;
}
 
int iniciar0(){
    int fd;
        fd = open("/sys/class/gpio/gpio250/value", O_WRONLY | O_SYNC);
        write(fd, "0", 1);
        close(fd);
        fd = open("/sys/class/gpio/gpio248/value", O_WRONLY | O_SYNC);
        write(fd, "0", 1);
        close(fd);
        fd = open("/sys/class/gpio/gpio173/value", O_WRONLY | O_SYNC);
        write(fd, "0", 1);
        close(fd);
        fd = open("/sys/class/gpio/gpio172/value", O_WRONLY | O_SYNC);
        write(fd, "0", 1);
        close(fd);
}
 
int iniciar1(){
    int fd;
        fd = open("/sys/class/gpio/gpio250/value", O_WRONLY | O_SYNC);
        write(fd, "1", 1);
        close(fd);
        fd = open("/sys/class/gpio/gpio248/value", O_WRONLY | O_SYNC);
        write(fd, "1", 1);
        close(fd);
        fd = open("/sys/class/gpio/gpio173/value", O_WRONLY | O_SYNC);
        write(fd, "1", 1);
        close(fd);
        fd = open("/sys/class/gpio/gpio172/value", O_WRONLY | O_SYNC);
        write(fd, "1", 1);
        close(fd);
}

hi @blazescreen

Welcome to the Toradex Community!!!

Could you provide the version of the hardware and software of your module?
Have you done the Getting Started, where you can configure the toolchain and do the cross compilation?

If no, how are you doing the compilation?