Thread: copy int to buffer??

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    64

    copy int to buffer??

    is it possible to copy a int to another int.
    fx, in sprintf you copty a string to a buffer..

    char buffer[80];
    sprintf(buffer, "An approximation of Pi is %f\n", M_PI);

    And the same goes for strcpy:
    char *strcpy(char *dest, const char *src);

    Can't it be done.
    fx. if I have:

    int x =10;
    int buffer; /* here i like the number to go */

    copy (buffer, "%d", x);

    is this possible, but what kind of function is copy going to be??
    tx..

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    You mean:

    Code:
    buffer = x;
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    64

    Talking

    LOL WOW..
    You got to be kidding me, how could I miss that...
    Maybe I reading so much about C, that the first I learned is popping out of my head...

    well tx for your answer...
    Very nice to have this forum...
    !G!

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Actually... you could use the memcpy function like so if you wanted to complicate things:

    Code:
    int x = 10;
    int buffer;
    memcpy( (void*) &buffer, (void*) &x, sizeof int );
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >Maybe I reading so much about C, that the first I learned is
    >popping out of my head...

    You read it, but you didn't learn it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  2. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  3. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM