Sunday, October 23, 2005

realloc

This shows realloc function

 

 

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

 

#define SILLYSTRING "abcedef"

 

void a(char **n)

{

     char *t;

     t = realloc(*n, strlen(SILLYSTRING) + 1);

     *n = t;                     /* even if realloc fails, in this case.

                                    Not a good idea as a rule */

     strcpy(*n, SILLYSTRING);

}

 

int main(void)

{

     char *nn = 0;

     a(&nn);

     if (nn)

         printf("nn points to \"%s\",\n nn[5] = %c\n", nn, nn[5]);

     free(nn);

     return 0;

}

 

 

Pradyut
http://pradyut.tk
http://spaces.msn.com/members/oop-edge/
http://groups-beta.google.com/group/oop_programming
India

 

No comments: