Jump to content

Help with reading a line please!


Recommended Posts

I WILL PAY YOU 1m in OSRS money if you can help me with this. I would offer more, but I feel like for a professional programmer, this would be easy.


Could someone tell me how to code this:


I'm reading this line from a file:


int variableName = 10; (this is stored in a String called data temporarily)


I need to push the variable name onto my stack, and then the actual value of the variable onto another stack.




Also note: the variableName can be any length up to 20 chars, and I think the value can be anything.


My attempt:

Alright, so I saw the split method in the String class. What I was thinking of doing was:

String[] sides = data.split("=");


Edited by Luffy
Link to comment
Share on other sites

No, it's part of my assignment.


The file the program is reading is a program in C.


Whenever the C program makes a variable, like int varName = 10;, I have to push the name of the variable into my stack, and the value of it into the other stack.


And then, eventually, it'll tell me to print all the local variables, at which point I pop the variables and their values, and print them, or it can tell me to only pop one of the specified variables.



Link to comment
Share on other sites

So your saying that

 int variableName = 10;

 is a string that you need to retrieve the value 10 from?


I've only done a little c++, but I would split the string from the 'space' and the ';' to get the value 10, then parse it to an int. I had code doing something similar for an assignment (again c++ not c) but cant find it on my hd sorry. 


Edited by emu
Link to comment
Share on other sites

This topic is now closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...