예제 #1
0
/* readCodeClient
* Descrição: realiza a leitura do código do Cliente inserido pelo usuário,
* fazendo a validação do mesmo quanto a ser um número inteiro e
* não haver outro código identico já alocado no sistema.
*/
int readCodeClient(void){

	int code;
	char entry[SIZE_CODE + 2];

	while(1){

		printf("Codigo: ");
		fgets(entry, SIZE_CODE + 2, stdin);

		/*Validação - Somente Inteiros*/
		if(validateNumber(entry) == TRUE){
			code = convertNumber(entry);

			/*Verificação - Árvore Vazia*/
			if(client_root->root != NULL){
				/*Validação - Código Duplicado*/
				if(searchClient(&(client_root->root), code) != NULL){
					printf("Codigo já cadastrado no sistema. Por favor, insira um novo codigo.\n");
				}else{
					break;
				}
			}else{
				break;
			}
		}
	}

	return code;
}
예제 #2
0
void PGuiVirtualMachine::readNumber()
{
    std::cout << "GUI readNumber" << std::endl;
    int read;
    do {
      read = QInputDialog::getInteger(
        0, "Piet input reading", "Enter a number:", 1);
    } while (!validateNumber(read));
    stack->instrPush(read);
}
예제 #3
0
파일: SPConfig.c 프로젝트: med3590/SPFinal
SP_CONFIG_MSG toPositiveNumber(char* valueStr, int* valueInt)
{
	SP_CONFIG_MSG msg = validateNumber(valueStr);
	if (SP_CONFIG_SUCCESS == msg)
	{
		*valueInt = atoi(valueStr);
		/* positive */
		if (0 >= *valueInt)
		{
			msg = SP_CONFIG_INVALID_INTEGER;
		}
	}

	return msg;
}
예제 #4
0
/*MAIN MENU
 * Displays main menu choices*/
void showMenu() {
    Cell board[BOARD_HEIGHT][BOARD_WIDTH];
    while (TRUE) {
        int choice;
        printf("\n");
        printf("Welcome to Car Board \n");
        printf("-------------------- \n");
        printf("1. Play game \n");
        printf("2. Show student's information \n");
        printf("3. Quit \n\n");
        choice = validateNumber();
        if (choice == 1) {

            showCommands();
            initialiseBoard(board);
            displayBoard(board, NULL);

            printf("load <g>\n");
            printf("quit\n\n");

            initialiseGame();
        }

        if (choice == 2) {

            showStudentInformation();
        }

        if (choice == 3) {

            printf("\n");
            printf("Good Bye!\n\n");

            break;

        }
    }
}
예제 #5
0
파일: ilpParser.c 프로젝트: AndreG-P/appfs
/*	This method shall be used only inside method createLPFromFile
	The numbers must be seperated by a delimiter (e.g whitespace)

	\return number of decimals read, -1 if number of coeffs in file does not match
*/
int fillRow(num* row, int col, char* inputString, char* delimiter) {
	int i = 0;
	int asInteger;
	float asFloat;
	char* brki;
	assert(NULL != inputString);
	assert(NULL != row);
	// Seperate each number
	char* value = strtok_r(inputString, delimiter, &brki);
	while (NULL != value) {
		if (i+1 > col) {
			printf("Number of columns more than specified in line 1!\n");
			return -1;
		}
		// Check if it is a number
		if (!validateNumber(value)) {
			return -1;
		}
		row[i] = atof(value);
		asInteger = atoi(value);
		asFloat = atof(value);
		
		// Check 
		if (((asFloat - asInteger) != 0) && !IS_DOUBLE) {
			return -1;
		}
		
		
		i++;
		// Next number
		value = strtok_r(NULL, delimiter, &brki);
	}
	if (i < col) {
		return -1;
	}
	return i;
}
예제 #6
0
파일: ThrowDice.c 프로젝트: syvjohan/CFun
void handleDiceInput() 
{
	int input = -1;
	do {
		_flushall();
		scanf(" %d", &input);
		if (validateNumber(&input) == 0) {
			if (validateUINTMAX(input) == 1 && validateMin(input) == 1) {
				castDice(input);
				setState(GS_MAINMENU);
#undef FLAGG
				manage(); //Go back to main menu.
			} else {
				printf("\nValue not in range!\n");
				drawDiceMenu();
				handleDiceInput();
			}
		} else {
			printf("\nInput value shall be a number!\n");
			drawDiceMenu();
			handleDiceInput();
		}
	} while (1);
}
예제 #7
0
파일: ilpParser.c 프로젝트: AndreG-P/appfs
/*
	\param filename the name of the file
*/
struct linearProgram* createLPFromFile(const char* filename) {
	assert(NULL != filename);
	
	mode = READ_COL;
	
	FILE* fp;
	char buffer[BUF_SIZE];
	char* s;
	int lines = 0;
	
	struct linearProgram* binaryLP;
	int numOfCols = 0;
	int numOfRows = 0;
	int currentConstraint = 0;
	char* type;
	
	if (NULL == (fp = fopen(filename, "r"))) {
		fprintf(stderr, "Can't open file %s\n",filename);
		printf(USAGE);
		exit(EXIT_FAILURE);
	}
	// need a helpful string for strtok
	char* help_me = allocate(BUF_SIZE, sizeof(*help_me));
	char* end_pos;
	char* test;
	char* brks;
	while(NULL != (s = fgets(buffer, sizeof(buffer), fp))) {
		end_pos = strpbrk(s, "#\n\r");
		if (NULL != end_pos) {
			*end_pos = '\0'; // terminate string here, now we can process this line		
		}
		
		/* Skip over leading space
		*/
		while(isspace(*s)) 
			s++;
		
		/* Skip over empty lines
		*/
		if (!*s) /* <=> (*s == '\0') */
			continue;
		
		if (mode == READ_COL) {
			lines++;
			numOfCols = parseDecimal(s);
			mode++;
		}
		else if (mode == READ_ROW) {
			lines++;
			numOfRows = parseDecimal(s);
			
			/* ready to allocate memory for binaryLP.coeffs, rhs-vector and types-enum */
			binaryLP = initializeLP(numOfCols, numOfRows);
			// ready to parse constraint matrix
			mode++;
		}
		else {
			assert(mode == READ_CONSTR);
			lines++;
			if (currentConstraint + 1 > binaryLP->row) {
				printf("Second decimal must correspond to number of constraints!\n");
				exit(EXIT_FAILURE);
			}
			if (NULL == (type = strpbrk(s, "<>="))) {
				printf("Constraint in line %d has wrong shape (<,> or = missing)!\n", lines);
				exit(EXIT_FAILURE);
			} // check which type of constraint
			setType(*type, currentConstraint, binaryLP->types);
			
			// TODO WTF
			strcpy(help_me, s);
			if (-1 == fillRow(binaryLP->coeffs[currentConstraint], binaryLP->col, strtok_r(s,"><=",&brks), " ")) {
				// free pointer:
				deleteLinearProgram(binaryLP);
				deallocate(help_me);
				printf("Incorrect number or format of coefficients in line %d.\n", lines);
				printf(USAGE);
				exit(EXIT_FAILURE);
			}
			//test = strtok(help_me, "><=");
			if(NULL == (test = strtok_r(NULL, " ><=", &brks))) {
				printf("No rhs in line %d.\n", lines);
				printf(USAGE);
				exit(EXIT_FAILURE);
			}
			if (!validateNumber(test)) {
				printf("No number on right-hand-side of line %d.\n", lines);
				exit(EXIT_FAILURE);
			}
			binaryLP->rhs[currentConstraint] = atof(test);
			if (NULL != (test = strtok(NULL, " "))) {
				printf("More than one value on right-hand-side of line %d!\n", lines);
				exit(EXIT_FAILURE);
			}
			currentConstraint++;
		}
	}
	if (currentConstraint < numOfRows) {
		printf("Too few rows!\n");
		exit(EXIT_FAILURE);
	}
	if (lines == 0) {
		printf("The file was empty! Nice try...\n");
		exit(EXIT_FAILURE);
	}
	free(help_me);
	
	fclose(fp);
	return binaryLP;
}
예제 #8
0
파일: SPConfig.c 프로젝트: med3590/SPFinal
SP_CONFIG_MSG assignValueToField(SPConfig config, char* fieldName, char* fieldValue)
{
	SP_CONFIG_MSG msg = SP_CONFIG_UNKNOWN_FIELD;

	if (0 == strcmp(FIELD_NAME_ImgDir, fieldName))
	{
		strcpy(config->spImagesDirectory, fieldValue);
		msg = SP_CONFIG_SUCCESS;
	}
	else if (0 == strcmp(FIELD_NAME_ImgPre , fieldName))
	{
		strcpy(config->spImagesPrefix, fieldValue);
		msg = SP_CONFIG_SUCCESS;
	}
	else if (0 == strcmp(FIELD_NAME_ImgSuf , fieldName))
	{
		msg = validateImagesSuffix(fieldValue);
		if (SP_CONFIG_SUCCESS == msg)
		{
			strcpy(config->spImagesSuffix, fieldValue);
		}
	}
	else if (0 == strcmp(FIELD_NAME_NumImg , fieldName))
	{
		/* validate that fieldValue is a positive number*/
		msg = toPositiveNumber(fieldValue, &(config->spNumOfImages));
	}
	else if (0 == strcmp(FIELD_NAME_PcDim , fieldName))
	{
		/* validate that fieldValue is a number*/
		msg = validateNumber(fieldValue);
		if (SP_CONFIG_SUCCESS == msg)
		{
			config->spPCADimension = atoi(fieldValue);
			/* between 10 to 28 */
			if (CONSTRAINT_MIN_DIMENSIONS > config->spPCADimension || CONSTRAINT_MAX_DIMENSIONS < config->spPCADimension)
			{
				msg = SP_CONFIG_INVALID_INTEGER;
			}
		}
	}
	else if (0 == strcmp(FIELD_NAME_PcFile ,fieldName))
	{
		strcpy(config->spPCAFilename, fieldValue);
		msg = SP_CONFIG_SUCCESS;
	}
	else if (0 == strcmp(FIELD_NAME_FeatNum , fieldName))
	{
		/* validate that fieldValue is a positive number*/
		msg = toPositiveNumber(fieldValue, &(config->spNumOfFeatures));
	}
	else if (0 == strcmp(FIELD_NAME_ExtarctMode , fieldName))
	{
		msg = toSPConfigBoolean(fieldValue, &(config->spExtractionMode));
	}
	else if (0 == strcmp(FIELD_NAME_SimImgNum , fieldName))
	{
		/* validate that fieldValue is a positive number*/
		msg = toPositiveNumber(fieldValue, &(config->spNumOfSimilarImages));
	}
	else if (0 == strcmp(FIELD_NAME_KdSplitMethod , fieldName))
	{
		msg = toSplitMethod(fieldValue, &(config->spKDTreeSplitMethod));
	}
	else if (0 == strcmp(FIELD_NAME_Knn, fieldName))
	{
		/* validate that fieldValue is a positive number*/
		msg = toPositiveNumber(fieldValue, &(config->spKNN));
	}
	else if (0 == strcmp(FIELD_NAME_MinGui , fieldName))
	{
		msg = toSPConfigBoolean(fieldValue, &(config->spMinimalGUI));
	}
	else if (0 == strcmp(FIELD_NAME_LogLevel , fieldName))
	{
		/* validate that fieldValue is a positive number*/
		msg = toPositiveNumber(fieldValue, &(config->spLoggerLevel));
		/* LogLevel should be between 1 to 4 */
		if (SP_CONFIG_SUCCESS != msg || CONSTRAINT_MAX_LOGLEVEL < config->spLoggerLevel)
		{
			return SP_CONFIG_INVALID_INTEGER;
		}
	}
	else if (0 == strcmp(FIELD_NAME_LogFile , fieldName))
	{
		strcpy(config->spLoggerFilename, fieldValue);
		msg = SP_CONFIG_SUCCESS;
	}

	return msg;
}