Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void carregaConfiguracoes(void){
- FILE * fp;
- fp = fopen(FILE_CONFIG,"r");
- config=(Configuracao*) malloc(sizeof(Configuracao));
- char buffer[100];
- int linha,i;
- //int max_x, max_y,n_drones,n_armazens,freq,quant,unid_tempo;
- //char prod[5][30];
- if ( fp != NULL)
- {
- linha = 0;
- int l=0;
- while((fgets(buffer,MAX_BUFFER,fp)) != NULL ){
- if ( linha == 0){
- char * token = ( char * ) malloc(MAX_BUFFER * sizeof(char));
- char * aux;
- strcpy(token,buffer);
- aux = strtok(token,",");
- config->maxX=atoi(aux);
- aux=strtok(NULL, "\n");
- config->maxY=atoi(aux);
- printf("%d x %d y\n", config->maxX, config->maxY);
- free(token);
- }
- if (linha == 1){
- printf("saltei linha nao sei o que faz\n");
- }
- if(linha == 2){
- config->numero_drones=atoi(buffer);
- printf("%d drone no sistema\n",config->numero_drones);
- }
- if(linha == 3){
- char * token = ( char * ) malloc(MAX_BUFFER * sizeof(char));
- token = strtok(buffer, ",");
- config->frequencia_abastecimento_s= atoi(token);
- token = strtok(NULL, ",");
- config->frequencia_abastecimento_q= atoi(token);
- token = strtok(NULL,"\n");
- config->frequencia_abastecimento_t = atoi(token);
- printf("%d s %d q %d t\n", config->frequencia_abastecimento_s,config->frequencia_abastecimento_q,config->frequencia_abastecimento_t);
- }
- if (linha==5){
- char * token = ( char * ) malloc(MAX_BUFFER * sizeof(char));
- token = strtok(buffer, ",");
- config->numero_armazens_sistema= atoi(token);
- printf("%d armazens no sistema\n",config->numero_armazens_sistema);
- }
- if (linha>5){
- for (int i=0; i<config->numero_armazens_sistema;i++){
- struct armazem *novoArmazem=malloc(sizeof(struct armazem));
- char * token = ( char * ) malloc(MAX_BUFFER * sizeof(char));
- token = strtok(buffer, ":");
- strcpy(string[0],token);
- token = strtok(NULL, ":");
- strcpy(string[1],token);
- token = strtok(NULL,"\n");
- strcpy(string[2],token);
- token = strtok(string[0], " ");//nome armazem
- strcpy(novoArmazem->nome, token);
- token = strtok(string[1], ",");
- novoArmazem->posX=atoi(token);
- token = strtok(NULL, " ");
- novoArmazem->posY=atoi(token);
- token =strtok(string[2], ", ");
- //printf("string--%s\n",token);
- int j=0;
- while(token !=NULL){
- struct produto *novoProduto=malloc(sizeof(struct produto));
- strcpy(novoProduto->nome, token);
- token = strtok(NULL, ", ");
- novoProduto->quantidade=atoi(token);
- token=strtok(NULL, ", ");
- //printf("%s \n", token);
- config->armazensSistema[i].produtos[j]=*novoProduto;
- printf("%s", config->armazensSistema[i].produtos[j].nome);
- j++;
- }
- config->armazensSistema[i]=*novoArmazem;
- printf("%s, %d, %d\n", config->armazensSistema[i].nome,config->armazensSistema[i].posX,config->armazensSistema[i].posY);
- fgets(buffer,MAX_BUFFER,fp); //passa linha
- }
- }
- linha++;
- }
- }
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement