Path: utzoo!attcan!uunet!cs.utexas.edu!mailrus!ncar!umigw!umiami!slores From: SLORES@umiami.miami.edu (Stanislaw L. Olejniczak) Newsgroups: comp.lang.c Subject: Q: Realloc of function parameter problem. Message-ID: <3752@umiami.miami.edu> Date: 26 Nov 89 16:27:07 GMT Organization: Univ. of Miami (IR) Lines: 38 I am trying to write a function which would, if neccessary, change the size of the string pointed to by one of the arguments, and return the pointer to the "new" string. It is part of a larger function. I seem to have a problem with realloc... I tried finding an answer in just about all the C books I have, but I simply cannot figure out WHY is it giving me problems. If you could tell me HOW to do this correctly, I would be most grateful. Any assistance would be welcome. code: ====================================================================== char *substr( char *, int, int, char **); main() { char *string="This is a test", *subs=""; int start = 3, numchar = 5; subs = substr (string, start, numchar, &subs); } char *substr (char *string, int start, int numchar, char **substr) { /*I get a variety of errors on the following statement, depending on a compiler/linker. The code bombs here, I guess because memory management is being damaged*/ *substr = (char *) realloc ( (unsigned) (numchar + 1), *substr); } ---- Stan Olejniczak Internet: slores@umiami.miami.edu University of Miami, FL USA UUCP: (temp void) gould!umbio!solejni SLORES@UMIAMI.BITNET UUCP: (?) umigw!gables!slores Voice: (305) 547-6571 FAX: (305) 548-4612 My opinions cannot possibly represent the views of anyone else!