Hello, I am trying to create some kind of parser for MathML. It takes a piece of text code and translates it from a more intuitive code to MathML in HTML.
I have set up the code the following way:
words[] is an array that holds every word in the original text(ex: a + dog, words[0] = "a", words[1] = "-", words[2] = "dog")
respectiveWords[] is an array that holds the processed HTML code. (ex: if the word "Omega" is detected in words[1], then respectiveWords[1] will be Ω - the HTML code for omega)
append[] is array of strings (ex: at the end of the program, when writing everything to file and after everything is processed, append[2] will be written after words[2]. The output will be practically respectiveWordw[0] + append[0] + respectiveWords[1] + append[1] +...
Now, I have the following piece of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
for(int i = 0; i<nWords; i++){
...
if(eq(words[i], "#")){
change(respectiveWords[i], "<msub><mi></mi><mi>");
if(eq(words[i+1], "(")){}
else if(eq(words[i+1],"fraction")){
cout<<"\nDETECTED FUNCTION - ANIHILATING\n";
int currentLevel = paranthesisLevel+1;
int j = i+2;
bool flag = true;
//HERE IS THE "WHILE" PROBLEM
while(flag == true){
if(eq(words[j], "(")){currentLevel++;}
else if(eq(words[j], ")")){
if(currentLevel == paranthesisLevel+1){
flag = false;
strcat(append[j], "</mi></msub>");
}
else{currentLevel--;}}
j++;}
}
else {strcat(append[i+1], "</mi><msub>");}}
...
bool eq(char* a, char* b) returns true if the 2 strings are the same (strcmp)
|
The problem is the following: that while, whether or not it is called, messes up the whole respectiveWords array, in that it makes every word of it "ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ...".
Now, if I change "while" to "if" it miraculously works and doesn't change anything.
Anyone knows what the problem might be?
EDIT: "The program messes things up even if it doesn't reach the while. For example, I never have a "#" in my code, so it never gets inside that if statement. Yet something in that while still ruins my array. If I just replace that "while" with "if", it works. How can that happen if it doesn't get inside the loop?"
EDIT2: Solved. I can't believe I'm retarded enough to completely not notice the "else" statement. Took me 3 days to see that line of code, god... the "append" array was initialized wrong.