int main(int argc, char const *argv[]) { char str[MAX]; printf("Inserire una stringa: "); scanf("%180s", str); printf("\n %s\n", (palindroma(str) == 1) ? "è palindroma" : "non è palindroma"); return 0; }
int main(int argc, char *argv[]){ DIR *d; struct dirent *dir; char *path; char args[1]; int fd[2]; //pipe fd for process sinc list lista = NULL; // char input[254]; int pid; //int count=0; int status; struct pollfd fds; //struct for poll d = opendir("."); if(d==NULL){ printf ("Non riesco ad aprire la directory corrente"); exit(1); } //opening the pipe for pollin if((pipe(fd)) == -1){ perror("Pipe"); return(EXIT_FAILURE); } fds.fd = fd[0]; fds.events=POLLIN; // fgets(input,254,stdin); while ((dir = readdir(d)) != NULL) { switch (pid=fork()) { case -1: printf("fork fail\n"); return(EXIT_FAILURE); break; case 0: if(strncmp(dir->d_name, ".", 1)){//ignora i file nascosti if(eseguibile(dir->d_name)&&palindroma(dir->d_name)){ //printf("%s è eseguibile\n", dir->d_name); path=malloc(strlen(dir->d_name)+3); strcpy(path, "./"); strcat(path, dir->d_name); printf("%s è il path \n", path); poll(&fds,1,-1); //struct poll, size of fds array and -1 for block until interrupt call //wait until all processes are ready myexec(path); perror(path); return(EXIT_FAILURE); } } }//end switch } write(fd[1], "g", 1); return(0); }