Thread: Use of Macro

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    8

    Use of Macro

    I compiled the following C program:
    Code:
    #include<stdio.h>
    #include<conio.h>
    #define str1 str[]
    int main()
    {
    clrscr();
    char str1="Come January";
    printf("%s\n",str1);
    return 0;
    }
    But it threw error..
    Can anyone point out where the error is and why is it coming?

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    printf("%s\n", str );

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    If it "threw an error", wouldn't you KNOW where it threw an error? No, this is a homework or interview question.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    While you're at it, be sure to tell them that str, and anything starting with str, is reserved.


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

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    are you sure it's not just starting with str and a lowercase letter?

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by robwhit View Post
    are you sure it's not just starting with str and a lowercase letter?
    Yes, and it really refers to function names. But it's easier to remember to just not use 'str*' for anything, than it is to remember that 'str1' is probably OK, and that 'stra' isn't, and that it's OK here, but not there. (It's more than likely never going to be an issue, but there's a chance.)

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Macro problem
    By TriKri in forum C Programming
    Replies: 6
    Last Post: 05-14-2010, 02:52 AM
  3. Replies: 2
    Last Post: 04-12-2010, 12:57 PM
  4. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  5. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM