#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <thread>
using namespace std;
struct sPokemon{
string nome;
string tipo;
int speed;
int util;
};
void lookname1(int n, sPokemon galardex[],string nome){
int start=0;
for(int i=start;i<n/2;i++){
cout<<"i e' "<<i<<endl;
if(nome==galardex[i].nome){
galardex[i].util++;
break;
}
}
}
void lookname2(int n, sPokemon galardex[],string nome){
int start=n/2;
for(int j=start;j<n;j++){
cout<<"j e' "<<j<<endl;
if(nome==galardex[j].nome){
galardex[j].util++;
break;
}
}
}
void inserisci(sPokemon galardex[],int n,string privileged_access){
int i;
string nome,fine;
thread t1,t2;
if(privileged_access==""){
do{
fflush(stdin);
getline(cin,nome);
t1= thread(lookname1,n,galardex,nome);
t2= thread(lookname2,n,galardex,nome);
t1.join();
t2.join();
}while(nome!="Fine");
}
else{
nome=privileged_access;
t1= thread(lookname1,n,galardex,nome);
t2= thread(lookname2,n,galardex,nome);
t1.join();
t2.join();
}
}
int main(int argc, char** argv) {
fstream f1;
int i,c=0;
string misc;
sPokemon galardex[1000];
f1.open("elenco.txt");
while(!f1.eof()){
f1>>misc;
if(c==0){
galardex[i].nome=misc;
c++;
}
else if(c==1){
galardex[i].tipo=misc;
c++;
}
else if(c==2){
galardex[i].speed= atoi(misc.c_str());
c++;
}
else if(c==3){
galardex[i].util= atoi(misc.c_str());
c=0;
i++;
}
}
int n=i;
f1.close();
int selett;
do{
cin>>selett;
switch(selett){
case 0:
inserisci(galardex,i,"");
break;
}
}while(selett!=0);
return 0;
}
So basically, i'm having a problem in the function inserisci, when i enter the privileged access if. It's supposed to let me enter a name, the program looks for the same name in the list, and if it finds it it ups it count by 1. However, when it's done checking the list, it just loops endlessly, when it is supposed to ask me for another name. I've tried removing the threads, but it isn't working regardless. So what may be the problem?