Thread: Realloc Problem

  1. #1
    Registered User
    Join Date
    Nov 2010

    Realloc Problem

    Hi everyone,

    I know its a basic problem, but realloc doesnt seem to be resizing my array to the right size.

    char* nickBuf=NULL;
    int reallocLength = 1024 + nickLength +1;
                  printf("size of reallocLength is: %d\n", reallocLength);		
    void *_tmp = realloc(nickBuf, reallocLength); 
                  printf("size of bufPlusNick inside if loop is: %d\n", sizeof(nickBuf));
                  //nickBuf is freed later on in code
    various printf statements i have have printed out the following

    size of reallocLength is: 2045
    size of nickBuf inside if loop is: 4
    size of nickLength is: 1020
    size of nickBuf is: 4

    im unsure how realloc can resize the array to only 4, when an int of 2045 is given as the argument

    thanks for any help

  2. #2
    Registered User
    Join Date
    May 2010

  3. #3
    Join Date
    Aug 2010
    Ontario Canada
    Size of nickBuf returns 4 because you are asking for the size of the pointer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. writing a pack-style function, any advices?
    By isaac_s in forum C Programming
    Replies: 10
    Last Post: 07-08-2006, 08:09 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. using realloc
    By bobthebullet990 in forum C Programming
    Replies: 14
    Last Post: 12-06-2005, 05:00 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM

Tags for this Thread