Thread: Declare an operator a variable?

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    23

    Smile Declare an operator a variable?

    Hello all!
    It's a brand new day and a brand new query. I would like to use an operator as a variable (in particular '*'). I want to print out a number of '*' horizontally that reflect the given value of another variable. I thought if I declared the '*' to be an int I could just include a fprintf statement ( after the fprintf statement that prints the value of the main variable ) and have it print a corresponding number of times on the same line if I don't use a new line command......... Thks greatly

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can't declare '*' as anything. You can easily display however many you want though:
    Code:
    void displaystar( int count )
    {
        int x;
        for( x = 0; x < count; x++ )
            putchar( '*' );
    }
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Identifyer names can only contain letters, digits and a few special characters, and must begin with a letter. This makes it impossible to name a variable *.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Magos
    Identifyer names can only contain letters, digits and a few special characters, and must begin with a letter. This makes it impossible to name a variable *.
    Must begin with a letter or an underscore. While they may or may not be considered 'reserved' to do so, it is valid:

    int _myvar;

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

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    23

    Smile

    Thanks citizens! I think I need to give this some more thought.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685

    Talking

    are you trying to tell me that my latest project won't work:

    Code:
    void main(void) {
        int ** = "hello world";
        int number_of_stärs = 1;
    
        for(;;) {
             * = (int *)malloc(sizeof(int));
        }
    
        return "NULL";
    }

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    23

    Smile

    I got my prog to work alright with just a for and print statement.
    Code:
    for(a=1; a <= num_a; a++)
    fprintf(outfile, "*",a);
    Value of num_a determined prior of course. Now on to the next assignment ......... Thks all
    Last edited by bluenoser; 10-18-2002 at 01:07 AM.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by master5001
    are you trying to tell me that my latest project won't work:

    Code:
    void main(void) {
        int ** = "hello world";
        int number_of_stärs = 1;
    
        for(;;) {
             * = (int *)malloc(sizeof(int));
        }
    
        return "NULL";
    }
    No, that should be fine as long as you are using MS VC++.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >No, that should be fine as long as you are using MS VC++.
    It wouldn't surprise me.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Variable name from another
    By Xinco in forum C++ Programming
    Replies: 5
    Last Post: 05-02-2007, 02:19 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM