// convert array of character from input to an array of integer int toIntArray(int *array,char in[],int j,char temp[],int limit){ if(j==strlen(in)+1){ l=0; return 1; }else if(in[j]!=' ' && in[j]!='\0'){ int len = strlen(temp); temp[len] = in[j]; j++; toIntArray(array, in, j, temp, limit); }else{ if (atoi(temp)>=-100 && atoi(temp)<=100){ if (atoi(temp)>=0 && l<=limit-1){ array[k]=atoi(temp); k++; } char p[256]=""; j++; l++; toIntArray(array, in, j, p, limit); } else{ return 0; } } }
//Receive the N input test cases void inputInt(int total){ int X; if (ctr==total){ printResult(result,ctr); } else{ scanf("%d",&X); scanf("%c",&trash); if (X>0 && X<=100){ scanf("%[^\n\t]s",input); char tmp[256]=""; int checkY = toIntArray(arr,input,0,tmp,X); // calculate result[ctr]=0; calculate(result,arr,k); ctr++; k=0; if (checkY==0){ printf("Please input Yn ( -100 <= Yn <= 100 )!\n"); return; } } else{ printf("Please input X ( 0 < X <= 100 )!"); return; } inputInt(total); } }
void display(const partialSolution &sol) { int intSolution[SUDOKU_GRID_SIZE][SUDOKU_GRID_SIZE]; toIntArray(sol,intSolution); for(size_t i=0; i<SUDOKU_GRID_SIZE; i++) { for(size_t j=0; j<SUDOKU_GRID_SIZE; j++) std::cout << intSolution[i][j] << ", "; std::cout << '\n'; } std::cout << '\n'; }
int[][] llenaDatos(char name[], int proces, int maximo) { FILE * pFile; char P [100]; int counter = 0; int valores[proces][maximo]; pFile = fopen (name , "r"); for(forX = 0; forX < times; forX++) { if (pFile == NULL) perror ("No se detectó %s!", name); else { fgets (P , 100 , pFile); valores[counter] = toIntArray(P, 1); fclose (pFile); } fputs(P, pFile); fputs("\n", pFile); int tempore = toIntArray(P, 0); if (max < tempore) max = tempore; } }
int write(char fileName[], int times, char text[]) { FILE * pFile; pFile = fopen ( fileName , "wb" ); char P [100]; int forX; int max = 0; for(forX = 0; forX < times; forX++) { printf("%s %d : ",text, forX+1); scanf("%s",P); fputs(P, pFile); fputs("\n", pFile); int tempore = toIntArray(P, 0); if (max < tempore) max = tempore; } fclose (pFile); //Guardado return max; }