May 19, 2016 at 7:04pm May 19, 2016 at 7:04pm UTC
I have a C program with a #define as follows :
#define MAIN_MSG "Testing"
I want to not have it hard coded but pass it to the routine as parameter and inside the routine assign it to a variable .
how can I do that?
May 19, 2016 at 7:22pm May 19, 2016 at 7:22pm UTC
but I don't want to hard code the msg , since I will be sending many msgs ..
May 19, 2016 at 7:25pm May 19, 2016 at 7:25pm UTC
Do you want to pass it in from the command line?
C++ is a compiled language. Either you hard code it, pass it in from the command line, read it from a file, or prompt the user for it. Those are about your only choices.
Last edited on May 19, 2016 at 7:40pm May 19, 2016 at 7:40pm UTC
May 19, 2016 at 7:45pm May 19, 2016 at 7:45pm UTC
hi this is what I want :
int main ()
{
send_msg ("Message1");
..
send_msg ("Message2");
}
May 19, 2016 at 8:03pm May 19, 2016 at 8:03pm UTC
oh I see , yes i understand
thanks
May 20, 2016 at 1:15am May 20, 2016 at 1:15am UTC
ok I am stuck again .
I have this declaration in program of a constant which I want to replace.
can I do that ? I tried strcpy but its not working.
#define MAIL_MESSAGE "Messaeg1"
void send_email(const char * message)
{
strcpy(message,MAIN_EMAIL_MSG );
}
void main()
{
send_email("Message2");
send_emial("Message3");
}
May 20, 2016 at 10:13am May 20, 2016 at 10:13am UTC
That shouldn't even compile:
1) You haven't defined
MAIN_EMAIL_MSG .
2) You're attempting to copy something into a
const char * .
It doesn't look like you're thinking clearly about what your variables are for. What is the
message parameter supposed to be for? What is
MAIL_MESSAGE supposed to be for? What is
MAIN_EMAIL_MSG supposed to be for?
Also, please use code tags when posting code, to make it readable:
http://www.cplusplus.com/articles/z13hAqkS/
Last edited on May 20, 2016 at 10:14am May 20, 2016 at 10:14am UTC
May 20, 2016 at 10:28am May 20, 2016 at 10:28am UTC
You should probably review Macros and Functions for a good bit before giving this another go. Also do not use void main, use int main instead.