float *posToFloat(char *input[], int pos){

	if(input[pos])
		return checkFloat(input[pos]); //Credo che sia possibile aggiungere controlli di sicurezza..

	return NULL;
}
Example #2
0
string checkReal(double val)
{
    if (strcmp(ifloat(), "float") == 0) {
        return checkFloat(val);
    } else {
        return checkDouble(val);
    }
}
float *flagToFloat(char *input[], char *flag){

	int i=0;

	while (input[i]){
		if(strcmp(input[i],flag)==0){ //Flag trovato!
			if(input[i+1])        //Controllo anzi tutto che ci sia qualcosa dopo di lui
				return (float*) checkFloat(input[i+1]); //Poi controllo che sia un Float, e in caso lo restituisco
		} else i++; //Flag non trovato, procedo...
	}

	return NULL; //Se sono arrivato qui, il flag non e' stato trovato.
}
void test(const char * str){
	bool bInt = checkInt(str);
	bool bFloat = checkFloat(str);

	std::cout << "str: " << str << std::endl;

	if(bInt){
		int i = convertStr2Int(str);
		std::cout << "int: " << i << std::endl;
	}

	else if(bFloat){
		double f = convertStr2Float(str);
		std::cout << "float: "<< std::fixed << f << std::endl;
	}

}
/********************************************** MAIN FUNCTION *************************************************/
int main()
{
	int v, i, j, index1, index2, integers1[1000] = {0}, integers2[1000] = {0}, number1, number2;
	char start[100], key[100], s[100];
	scanf("%s", s);
	v = checkFloat(s);
	getchar();
	if(v < 0 || v > 1000 || v == -1)
	{
		printf("INVALID INPUT\n");
		return 0;
	}

	struct Graph *graph = makeGraph(v);

	for(i = 0; i < 10000; i++)
	{
		visited[i] = 0;
	}

	char input[1000][1000], weight[1000][1000];
	for(i = 0; i < v; i++)
	{
		scanf("%[^\n]s", input[i]);
		getchar();
	}

	for(i = 0; i < v; i++)
	{
		scanf("%[^\n]s", weight[i]);
		getchar();
	}

	for(i = 0; i < v; i++)
	{
		index1 = convertInput(input[i], integers1);
		index2 = convertInput(weight[i], integers2);

		if(index1 == -1 || index2 == -1)
		{
			printf("INVALID INPUT\n");
			return 0;
		}

		for(j = 0; j < index2; j++)
		{
			if(integers2[j] < 0 || integers2[j] > 10000)
			{
				printf("INVALID INPUT\n");
				return 0;
			}
		}
		
		if(index1 > 0)
		{
			if(isSorted(integers1, index1) == 0)
			{
				printf("INVALID INPUT\n");
				return 0;
			}
		}

		for(j = 0; j < index1; j++)
		{
			if(integers1[j] < 0 || integers1[j] > (v - 1))
			{
				printf("INVALID INPUT\n");
				return 0;
			}
			makeEdge(graph, i, integers1[j], integers2[j]);
		}
	}
	
	while(1)
	{
		char choice[5];
		scanf("%s", choice);
		if(strcmp(choice, "apsp") == 0)
		{
			scanf("%s", start);
			number1 = checkFloat(start);
			if(number1 < 0 || number1 > (v - 1))
			{
				printf("INVALID INPUT\n");
				return 0;
			}

			dijkstra(graph, number1);
			for(i = 0; i < graph->v; i++)
			{
				if(min_dist_array[i] != 50000)
				{
					printf("%d ", min_dist_array[i]);
				}
				else
				{
					printf("INF ");
				}
			}
			printf("\n");
		}
		else if(strcmp(choice, "sssp") == 0)
		{
			scanf("%s %s", start, key);
			number1 = checkFloat(start);
			if(number1 < 0 || number1 > (v - 1))
			{
				printf("INVALID INPUT\n");
				return 0;
			}

			number2 = checkFloat(key);
			if(number2 < 0 || number2 > (v - 1))
			{
				printf("INVALID INPUT\n");
				return 0;
			}
			dijkstra(graph, number1);
			if(min_dist_array[number2] != 50000)
			{
				printf("%d", min_dist_array[number2]);
			}
			else
			{
				printf("UNREACHABLE");
			}
			printf("\n");
		}
		else if(strcmp(choice, "stop") == 0)
		{
			break;
		}

		else 
		{
			printf("ENTER CORRECT CHOICE\n");
		}
	}
}
		static bool equal(const EERIEMATRIX &mat, const EERIEMATRIX &other) {
			return  checkFloat(mat._11,other._11) && checkFloat(mat._12,other._12) && checkFloat(mat._13,other._13) && checkFloat(mat._14,other._14) &&
					checkFloat(mat._21,other._21) && checkFloat(mat._22,other._22) && checkFloat(mat._23,other._23) && checkFloat(mat._24,other._24) &&
					checkFloat(mat._31,other._31) && checkFloat(mat._32,other._32) && checkFloat(mat._33,other._33) && checkFloat(mat._34,other._34) &&
					checkFloat(mat._41,other._41) && checkFloat(mat._42,other._42) && checkFloat(mat._43,other._43) && checkFloat(mat._44,other._44);
		}
void ReportReader::read(std::string filepath, ReportEntity& entity)
{
	std::cout <<filepath<<std::endl;

	static char buff[LINE_BUFF_LEN] = {0};	
	std::ifstream fs(filepath);

	//read header
	if(fs.good())
	{
		memset(buff, 0, sizeof(buff));
		fs.getline(buff, LINE_BUFF_LEN);
		std::string header(buff);

		std::vector< std::string > ret;
		split(header, ";", ret);


		entity.headerAddField("Line num");
		for(std::vector< std::string>::iterator iter = ret.begin();
			iter != ret.end(); ++iter)
		{
			//std::cout << *iter << "|";
			entity.headerAddField(*iter);
		}

		//std::cout << std::endl;
	}

	int linenum = 0;
	while(fs.good())
	{
		memset(buff, 0, sizeof(buff));
		fs.getline(buff, LINE_BUFF_LEN);
		std::string content(buff);

		linenum +=1;
		ReportEntity::ReportRow row;
		ReportEntity::rowAddField(row, linenum);
		//row.push_back(ReportEntity::shareRow(new DataBase(linenum)));

		std::vector< std::string > ret;
		split(content, ";", ret);
		for(std::vector< std::string>::iterator iter = ret.begin();
			iter != ret.end(); ++iter)
		{
			const char *char_str = iter->c_str();
			if(checkInt(char_str)){
				int i = convertStr2Int(char_str);
				ReportEntity::rowAddField(row, i);

			}else if(checkFloat(char_str)){
				double d = convertStr2Float(char_str);
				ReportEntity::rowAddField(row, d);

			} else if(checkNil(char_str)){
				ReportEntity::rowAddField(row, NilData);

			} else {
				ReportEntity::rowAddField(row, *iter);
			}

			//std::cout << *iter << "|";
		}

		entity.contentAddRow(row);
		//std::cout << std::endl;
	}
}