I started working with MIPS a couple of months ago and now I need to edit a given string so that it will only display the digits, arithmetic symbols and parenthesis that were in the original string as output. I though I could go ahead an print every string that was a digits, arithmetic symbols and parenthesis with beq instructions and do nothing if it was not. However, I'm supposed to print only when I reach an arithmetic symbol.
I was also given a print function that will print a given string, character by character. I can't change this function.
For example, "17+42/1638a" as input is supposed to give the following output:
In main, original formula: 17+42/1638a
17+
17+42/
In main, cleaned formula: 17+42/1638

How can I create a string of variable length in the middle of a function, so I can pass it to the printing function.

You can't.

What you can do, though, is have another string with all your other data, which you use to copy the valid characters to from the original string. Once you find a punctuation character, print the second string using the function given to you, then use the second string again in the same way until the original string is used up.

So your original idea will work except that instead of printing each character as you find it you just copy it to the end of a second string, which you print when you find a punctuation character.

Hope this helps.

Thanks, that's what I'll do, but it looks like I have to overwrite the original string and keep track of two counters.

Yes, you will need two counters. But I don't see why you will ever have to modify the original string. You will have to overwrite the second string several times...

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.