I'm making a graph theory problem solver and basically I made a bunch of functions that will set up the graph and allow the user to modify the graph, but obviously these functions can only be called from the program. The user can't just type the function name and expect the function to be called unless I do a lot of string parsing. For example, for the function, initGraph(graph *g, bool directed), I have to do the following,

if (command.length() > 10){
	if (command.substr(0, 9) == "initGraph") {
		if (command.substr(10, 1) == "1")
			directed = 1;
		else if (command.substr(10, 1) == "0")
			directed = 0;
		if ((i >= 0 && i <= 9) && (directed == 1 || directed == 0)) {
			g[i] = new graph();
			initGraph(g[i], directed);
			i++;
		}
	}
}

(Even though my function takes two parameters I only made it so the user has to input one. Most functions require the user to input both parameters.)
I haven't even added the code to make sure there are parenthesis around the parameters and other small details. Other functions also have more complex parameters so string parsing is possible but it is a very long process. Is there a better way to do it without all of this parsing?

may be using switch , u can give me options on wat he want to do .
And then call the corresponding functions for the option he chooses.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.