|
|
hi. I am trying to create a simple interpreter wherein it simply adds and subtracts.
Sample Input:
y = 5 + 8;
cout << y;
Output: 13
I have already started using stacks however it seems that it cannot pass through other commands after reading the input. Here's the code (Actually, I got this code from the net but it seems not to work):
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
stack<string> syntax;
string word;
while (cin >> input) //after this, it no longer passes to the next syntax
{
syntax.push(word);
}
cout << "Number of words: " << syntax.size() << endl;
while(!syntax.empty())
{
cout << syntax.top() << endl;
syntax.pop();
}
cout.flush();
return 0;
}
Do you have any ideas?
|
|
|
|
|
harcaype wrote: Do you have any ideas?
Definitely!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Definitely!
I know you're a creative guy.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
harcaype wrote: Do you have any ideas?
Personally not, however I know a creative guy [^].
BTW: properly format you code snippet using the code block button.
BTW2: are you using this code without properly understanding the underlying idea? At a first glance it looks rather buggy.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
harcaype wrote: while (cin >> input) //after this, it no longer passes to the next syntax
...
Do you have any ideas?
Yes. Fix the syntax error.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
well... that's my point. I can't seem to find any way to fix it. It runs but I don't know what logical error I'm doing. It does store the input in the stack but it no longer goes to the next line of codes after the while loop. Please help.. (T_T)
|
|
|
|
|
harcaype wrote: I can't seem to find any way to fix it.
The code snippet you've shown does not compile.
harcaype wrote: ...but it no longer goes to the next line of codes after the while loop.
Have you tried pressing F6 followed by the Enter key (twice).
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
wait. im sorry about that. this is the right code.
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
stack<string> syntax;
string word;
while (cin >> word)
{
syntax.push(word);
}
cout << "Number of words: " << syntax.size() << endl;
while(!syntax.empty())
{
cout << syntax.top() << endl;
syntax.pop();
}
cout.flush();
return 0;
}
|
|
|
|
|
Hi All,
I want to attempt to block a specific program from establishing outgoing TCP/UDP connections. Thus as the (external) app attempts to make a socket connection, I want to receive notification of the event and have the ability to allow or deny the connection attempt.
(I know this is basic firewall functionality I am referring to here, but there is no firewall on the market that can do exactly what I want, when I want, and how I want it for this specific program)
I have seen the packet filtering API that is provided by Windows, but that only seems to filter on IP's and Ports. I want to filter on application !
Can anybody please point my nose in the right direction here.
Thanks
OD
VC++ .NET 2002 on Windows XP and above ...
|
|
|
|
|
Try implementing a Layered Service Provider. This is a DLL that gets loaded by every application that uses Winsock.
Look up Winsock Layered Service Provider, or LSP.
“Cannot find REALITY.SYS...Universe Halted.”
~ God on phone with Microsoft Customer Support
|
|
|
|
|
Hi all,
I am currently working a specific hardware device and the device header files do not support some of the standard C string routines. Thus I am struggling to convert a int to a char* .
Thus, how can I perform this action without making use of itoa, printf, sprintf ??
Many thank in advance
Kind regards,
The only programmers that are better those C programmers are those who code in 1's and 0's |
Programm3r
My Blog: ^_^
modified on Wednesday, October 22, 2008 10:38 AM
|
|
|
|
|
Examine the source code of a standard C-RTL and steal^H^H^H^H^H , er... get some inspiration from... their implementation.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Here's how the CRT does itoa(), with all the error/buffer overflow checking stripped...
void integertoascii(int n, char *buf, int radix)
{
char *pbuf = buf;
do
{
unsigned int digit = (unsigned int)(n % radix);
n /= radix;
if (digit > 9)
*pbuf++ = digit - 10 + 'a';
else
*pbuf++ = digit + '0';
}
while (n > 0);
*pbuf-- = '\0';
do
{
char temp = *pbuf;
*pbuf = *buf;
*buf = temp;
--pbuf;
++buf;
} while (buf < pbuf);
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am installing my mfc based application through a .msi file.
i want to know how to close a running application before uninstallation???
|
|
|
|
|
Implement a small DLL that closes the application by sending a WM_CLOSE message to the main window.
Then call the DLL through a Custom Action in your MSI.
“Cannot find REALITY.SYS...Universe Halted.”
~ God on phone with Microsoft Customer Support
|
|
|
|
|
Hi Richard,
I got your point.Can you give me some detail info may a sample code as i am new to this thing.
Tarun.
|
|
|
|
|
Hello everyone,
How to get the preferred load address for a DLL? Suppose I just have the binary DLL and no source code?
thanks in advance,
George
|
|
|
|
|
You can use ListDLLs[^] to list currently loaded dlls.
If you use the -r switch it will flag up any dlls that have been relocated, and give you their preferred base.
Or Process explorer[^] has a dlls window which lists all the dlls loaded for each process, their base address, their preferred base address, and colours them yellow if they have been relocated.
Simon
|
|
|
|
|
Hi Simon,
Which Window in Process Explorer lists loaded DLLs for a process? I can not find out.
regards,
George
|
|
|
|
|
From the view menus, select the "Show lower pane options"
Then again from the view menu select "view->Lower pane view->dll"
|
|
|
|
|
Thanks nave,
DLL is displayed, but the DLL properties only display load address, no preferred load address. Any comments?
regards,
George
|
|
|
|
|
You can select that column also.
take the select column option by right clicking on the header of the lower pane. Select the "Base" and "Image Base" from the list. The "base" is the address at which the dll has actually loaded and "Image base" is the prefered base address.
You can also use the dependency walker to find the prefered base address.
|
|
|
|
|
Thanks nave!
I have found out, very good tool!
regards,
George
|
|
|
|
|
On my system at least,
dumpbin /headers iain.dll
then look at the image base value.
That's with VS6 - no idea if the utility is still around for later versions.
Iain.
|
|
|
|