Have you tried executing the application from the commandline?
\t
Main Topics
Browse All TopicsIm learning C++ from the book C++ progarmming languages (bjarne stroustrup).
I ran one of his little app and something went.. well not wrong but different then what expected..
is argc working for mac?
I mean I tried that app with and without argc and it did make a difference..
so it seems useless for mac (or unsuported?)
a hint anyone?
Luigi
Using project builder on OS 10.2.3
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
the main function uses argc.
bjarne says that if u name the app "dc" for exemple.
writing "dc 3*2" should return 6.
but when I compile this code.
just wont work.
but in the other hand, writing down "3*2" will work.
so thats why im asking if argc works for mac..
(ofc I made some test before concluding..)
here is the full thing from bjarne's book :
/*************************
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <cctype>
using namespace std;
/*************************
enum Token_value
{
NAME, NUMBER, END,
PLUS='+', MINUS='-', MUL='*', DIV='/',
PRINT=';', ASSIGN='=', LP='(', RP=')',
};
Token_value curr_tok = PRINT;
double number_value;
string string_value;
map<string,double> table;
int no_of_errors;
istream* input; //pointer to input stream
/*************************
double expr(bool get);
double term(bool get);
double prim(bool get);
Token_value get_token();
double error(const string& s);
/*************************
int main(int argc, char* argv[])
{
switch (argc)
{
case 1 : // read from standard input
input = &cin;
break;
case 2 :
input = new istringstream(argv[1]); // read argument string
break;
default :
error ("Too many arguments");
return 1;
}
table["pi"] = 3.1415926535897932385; // insert predefined names
table["e"] = 2.7182818284590452354;
while (*input)
{
get_token();
if (curr_tok == END) break;
if (curr_tok == PRINT) continue;
cout<< expr(false) <<endl;
}
if (input != &cin) delete input;
return no_of_errors;
}
/*************************
double expr(bool get) // add and substract
{
double left = term(get);
for(;;)
switch (curr_tok)
{
case PLUS :
left += term(true);
break;
case MINUS :
left -= term(true);
break;
default :
return left;
}
}
double term(bool get) // multiply and divide
{
double left = prim(get);
for (;;)
switch (curr_tok)
{
case MUL :
left *= prim(true);
break;
case DIV :
if (double d = prim(true))
{
left /= d;
break;
}
return error("Divide by 0");
default :
return left;
}
}
double prim(bool get) // handle primaries
{
if (get) get_token();
switch (curr_tok)
{
case NUMBER : // floating point constant
{
double v = number_value;
get_token();
return v;
}
case NAME :
{
double& v = table[string_value];
if (get_token() == ASSIGN) v = expr(true);
return v;
}
case MINUS : // unary minus
return -prim(true);
case LP :
{
double e = expr(true);
if (curr_tok != RP) return error("')' expected");
get_token(); //eat ')'
return e;
}
default :
return error("primary expected");
}
}
Token_value get_token()
{
char ch = 0;
do { if(!cin.get(ch)) return curr_tok = END; } // skip whitespace except '\n'
while (ch != '\n' && isspace(ch));
switch (ch)
{
case 0 :
return curr_tok=END;
case ';' :
case '\n' :
return curr_tok = PRINT;
case '*' :
case '/' :
case '+' :
case '-' :
case '(' :
case ')' :
case '=' :
return curr_tok = Token_value(ch);
case '0' : case '1' : case '2' : case '3' : case '4' :
case '5' : case '6' : case '7' : case '8' : case '9' :
case '.' :
cin.putback(ch);
cin >> number_value;
return curr_tok = NUMBER;
default: // NAME, NAME =, or error
if (isalpha(ch))
{
string_value = ch;
while (cin.get(ch) && isalnum(ch)) string_value.push_back(ch)
cin.putback(ch);
return curr_tok = NAME;
}
error("Bad Token");
return curr_tok = PRINT;
}
}
double error(const string& s)
{
no_of_errors++;
cerr << "error : " << s << '\n';
return 1;
}
From my experience, argc and argv work just fine in mac os x.
I think you need to make sure you run from the command line. You're using mac os x, right? Start up a terminal, and find the program of interest. Lets say you called it "dc_test". Did you try
./dc_test 3 * 2
./dc_test 3*2
Just as an aside, I think the Stroustrup book is the wrong one to learn C++ from. Would you learn to drive a car from the manual that comes in the glove box? At the very least, you should check his web page for errata and check the example you are using. There is quite a bit of errata for many examples in his book, including the example you have cited.
http://www.research.att.co
Business Accounts
Answer for Membership
by: orangehead911Posted on 2003-02-13 at 12:15:33ID: 7944668
Which type of project did you create?
Have you downloaded the December 2002 Dev Tools update?
\t