--- In [email protected], Robert Ryan <[EMAIL PROTECTED]> wrote: > > #include <stdio.h> > > int add (int x, int y) { > int z; > z = x + y; > return (z); > } > main () > { > int i, j, k; > i = 10; > j = 20; > k = add(i, j); > printf ("The value of k is %d\n", k); > } > how do you change the above code to the following > > + (2, 6) > - ( 2, 6)
Hi Robert, you mean, you want to enter a string like +(34,27) and expect the program to analyse and execute this expression? If my suggestion is correct, then you should look for topics named Syntax Analysis, String Parsing, and Tree Traversion; string parsing means to automatically "understand" that +(34,27) consists of the following "tokens": + ( 34 , 27 ) Syntax analysis means to automatically "understand" that these "tokens" are indeed useful in the order above. After the syntactical analysis of the sample strings above, you will need some means of storing the tokens in some useful manner. This is usually done as a "by-product" of the syntactical analysis; one common data structure to store such "syntax trees" are n-ary trees (for example, binary trees are 2-ary trees) which you then have to process and use yourself. This process of "wandering" around a tree and use the values stored within it is called "traversing" a tree. Maybe of course that I completely misunderstood you; in this case, could you please re-phrase your question? Regards, Nico
