int main(int argc, char *argv[]){ int i, fd; int aux = NUMBER_OF_LINES*POSITION_OF_NEWLINE; void* status; char* buf = (char*)malloc(sizeof(char)*(aux+1)); srand(time(NULL)); file = fileSelector(); if (argv[1]==NULL) { printf("Insert value for K\n"); return 0; } else k = strtol(argv[1], NULL, 10); if((fd = open(file, O_RDONLY)) < 0){ perror("Cannot open file"); exit(-1); } (read(fd, buf, aux)); letter = buf[0]; if((close(fd))< 0){ perror("Failed to close file"); exit(-1); } if (k > NUMBER_OF_LINES){ printf("Invalid K\n"); exit(-1); } for(i = 0; i < k; i++){ if (i==k-1) lastThread=1; if(pthread_create(&tid[i], NULL, reader, &i) != 0){ perror("Failed to create thread"); exit(-1); } else printf("Foi criada a tarefa %d\n", (int)tid[i]); if (result==-1) break; } printf("Resultado: %d\n", result); exit(0); }
std::string show_file_selector( const std::string& title, const std::string& initialPath, const std::string& showExtensions, FileSelectorType type, FileSelectorDelegate* delegate) { if (Preferences::instance().experimental.useNativeFileDialog() && she::instance()->nativeDialogs()) { she::FileDialog* dlg = she::instance()->nativeDialogs()->createFileDialog(); if (dlg) { std::string res; dlg->setTitle(title); dlg->setFileName(initialPath); if (type == FileSelectorType::Save) dlg->toSaveFile(); else dlg->toOpenFile(); std::vector<std::string> tokens; base::split_string(showExtensions, tokens, ","); for (const auto& tok : tokens) dlg->addFilter(tok, tok + " files (*." + tok + ")"); if (dlg->show(she::instance()->defaultDisplay())) res = dlg->fileName(); dlg->dispose(); return res; } } FileSelector fileSelector(type, delegate); return fileSelector.show(title, initialPath, showExtensions); }