Thread: Macros

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    63

    Macros

    I just did an assignment too quickly so I want to make sure that I did it right. It works properly but seems too easy to be true.

    The assignment says to write a program that defines and uses macro SUMMARY to sum the values in a numeric array. The macro should recieve the array and the number of elements in the array as arguments.

    I was not sure if I am supposed to somehow add the elements when I define it or as I did which works fine. Any advise is appreciated thanks.

    Code:
    #include <stdio.h>
    #define SUMMARY (total)
    #define SIZE 10
    
    
     
    int main() /* program main begins execution */
    {
       int A[SIZE] ={1,2,3,4,5,6,7,8,9,10}; /* define array */
       int i;    /* counter */
       int total = 0;  /* initialize total to zero */
    
       for (i=0; i< SIZE; i++ )  {    /* compute total */
        total += A[i];
       }
       printf( "Total value of array is %d\n", SUMMARY  ); /* print results */
    
       return 0;  /* indicates successful program execution */
    }

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Well, considering your macro doesn't meet the requirements ("The macro should recieve the array and the number of elements in the array as arguments.") then I'd say it's too good to be true.

    Your macro isn't receiving anything, and it certainly isn't doing any summing.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    63
    Thanks for nothing, this is a help board itsme86, just wanted some help, maybe a pointer, sorry to trouble you.

    Code:
    #include <stdio.h>
    #define SIZE 10
    #define SUMMARY(A,SIZE) {int i;int total=0;for(i=0;i<SIZE;i++){total += A[i];}printf("The sum of array elements is %d\n",total);}
    
    int main() /* program main begins execution */
    {
    int A[SIZE] ={1,2,3,4,5,6,7,8,9,10}; /* define array */
    SUMMARY(A,SIZE);
    return 0;  /* indicates successful program execution */
    }

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Nothing? I told you how and why your program didn't meet the assignment requirements. Details that you were previously unaware of. I even told you which details you blissfully ignored. No pointer? No help? What did you want? Someone to write the macro for you?
    If you understand what you're doing, you're not learning anything.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by itsme86
    What did you want? Someone to write the macro for you?
    You should know better by now! Of course that's what they wanted. No one comes here to actually learn anything. They all just want their homework done for them.

    Oh, and a note to the OP, I'll be adding you to my "never help this loser" list for a few reasons. Such as being an ungrateful, lazy, ass.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    63
    Message Board Rules

    edit....
    Be polite, especially if you want someone to help you. Keep in mind that being helpful does not give license to be rude.
    ....edit

    I wrote my own code.
    Posted it and asked a question.
    As I said that I thought that my code needed to be reformated to fit the requirements.

    And I was right, I just needed to move the loop inside of the macro definition, which instead of pointing out, or simply ignoring, you felt the need to basically say that it was completely wrong and how dare I think it was even close. Like your "gawking at stupidity" slogan, real classy for a help board.

    Sorry, I'm not the kid who picked on you in high school when you were playing D&D at lunch, to each his own. I'm new to programming and am going to stumble through some things.

    I am sure that you were born with code in your head and all but some of us aren't. I would completely understand if I just posted the assignment and waited for someone to write code for me, I help a lot of people on a calculus board and it drives me crazy, but I attempted the assignment as best as I could. Got it to compile and spit out the right anwser, but I felt that it was still not right, so I asked, sorry you had the gawk at stupidity.

    If thats your idea of helping people, start a new post called "programming gods" and rub each others egos. But this is a help board, don't use me to try to feel better about yourself, its not my fault.

    btw, its one word quzah-

    "You can teach a man to code... Well, you can try. Some ass hole will just come along and do his homework for him anyway."
    Last edited by jsbeckton; 11-30-2005 at 10:13 AM.

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    This is you saying your macro should recieve arguements.
    The macro should recieve the array and the number of elements in the array as arguments.
    This is your macro not recieving arguements.
    Code:
    printf( "Total value of array is %d\n", SUMMARY  ); /* print results */
    This is you thanking the person that pointed that out.
    Thanks for nothing, this is a help board itsme86, just wanted some help, maybe a pointer, sorry to trouble you.
    This is part of the quote from the guidelines you posted that you decided not to make bold.
    Be polite, especially if you want someone to help you.
    This is you whining when people scolded you for your rude replies.
    Sorry, I'm not the kid who picked on you in high school when you were playing D&D at lunch, to each his own. I'm new to programming and am going to stumble through some things.
    This is you dreaming that by knowing how to fix this simple code, you must be a "programming god."
    If thats your idea of helping people, start a new post called "programming gods" and rub each others egos. But this is a help board, don't use me to try to feel better about yourself, its not my fault.
    You must be at that wonderful age where you think you've figured it all out and that you're no more fallible than anyone else. I'm here to tell you that you're on the losing end of an arguement you shouldn't have started in the first place, and with each person you attempt to defend against, you lose more respect from everyone who has yet to shut you up but hasn't yet. People like you have short lifespans on forums like this. You make a dicky comment, ........ a few people off and leave without cleaning up the mess.

    Now I'm sure, that some of the people who don't like you right now would be willing to give you a chance and maybe help you again if you decided to apologize for acting like a disrepectful little brat.


    ...and I really, really don't need the moderators on my back about this one for talking down to this person. Right now, he deserved it.
    Sent from my iPadŽ

  8. #8
    Registered User
    Join Date
    Oct 2005
    Posts
    63
    I was completely polite until I was looked down on by someone after I humbly admitted that I neded help, the rest of your argument is unvalid. Im not perfect, I can't spell, can't program, can't do a lot of things but I can stand up for myself and call someone out for disrespect on a message board.

    I did not intend to make this a big argument, like I said I would understand if I had asked someone to do this for me but I did not. Looking back, if I had read the post from someone without the term "gawking at stupidity" under their name, perhaps I would have been less offended, Perhaps not. He is certaially free to have whatever he wants there but it doesn't give off the " I'd like to help you" vibe. Which is fine, but don't be suprised if people take your offhand comments the wrong way.

  9. #9
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    itsme86 has had the "Gawking at Stupidity" usertitle for as long as I've been here. It's not directed at anyone in specific and it's not like he changed it just for you and this post. What you need to do is reread itsme86's post and tell me where you find it offensive cause as far as I can see, he said nothing offensive at all.

    The regulars at this board have seen tons of disrespect for the work they've provided and way less appreciation than they deserve. When you reply with something rude (and I mean downright rude) as "Thanks for nothing", it just makes you look like you were exepecting someone to do the work for you.

    ...and lastly, you say you're not perfect and you can't spell, but you still insisted on making a rediculous out of the blue correction on Quzah's signature? I'm sure you're not a bad person, but you are doing a bad thing and that thing is not looking at this from our perspective. If you can do that, then you can see where you really stand, right now.
    Sent from my iPadŽ

  10. #10
    Registered User
    Join Date
    Oct 2005
    Posts
    63
    If he did not make that statement as a I recieved it, then I am sorry.

  11. #11
    Registered User
    Join Date
    Oct 2005
    Posts
    63
    Quote Originally Posted by jsbeckton
    If he did not make that statement as a I recieved it, then I am sorry.
    I really do appreciate all fo the help that people have given me on this board, its just a bit frustrating sometimes when you feel like people are treating you like an idiot because you need help.

    I'd say that its a overwhelming minority but you see it sometimes on these boards, perhaps it was that usertitle and the blunt comment togather that pushed me over the edge.

  12. #12
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    My reply was not meant to give offense. Reading this might help clear things up for you: http://www.catb.org/~esr/faqs/smart-....html#keepcool

    I don't post here to find pleasure in making fun of people that are asking for help. I enjoy helping people with programming that have a sincere interest in learning.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Order of execution of preprocessor macros
    By DL1 in forum C Programming
    Replies: 2
    Last Post: 04-02-2009, 06:52 PM
  2. Pre-processor macros causing segfaults
    By nempo in forum C++ Programming
    Replies: 6
    Last Post: 02-10-2009, 02:35 AM
  3. Macros inside of macros
    By Chewie8 in forum C Programming
    Replies: 2
    Last Post: 02-24-2008, 03:51 AM
  4. Macros vs Inline Functions
    By vb.bajpai in forum C Programming
    Replies: 4
    Last Post: 08-02-2007, 11:51 AM
  5. template fn replacements for msg macros
    By Ken Fitlike in forum Windows Programming
    Replies: 17
    Last Post: 10-30-2002, 07:55 AM