Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!samsung!think!mintaka!mit-eddie!mit-amt!snorkelwacker!spdcc!merk!xylogics!cloud9!jjmhome!m2c!umvlsi!chittamu From: chittamu@umvlsi.ecs.umass.edu (Satish Kumar .C) Newsgroups: comp.lang.c Subject: Re: Q: Realloc of function parameter problem. Message-ID: <537@umvlsi.ecs.umass.edu> Date: 27 Nov 89 05:32:21 GMT References: <3752@umiami.miami.edu> Reply-To: chittamu@umvlsi.ecs.umass.edu (Satish Kumar .C) Organization: University of Massachusetts, Amherst Lines: 42 In article <3752@umiami.miami.edu> SLORES@umiami.miami.edu (Stanislaw L. Olejniczak) writes: >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. > What compiler are you using? I tried it under gcc and the Ultrix cc. It worked fine. Ofcourse I made one small change. Your last parameter to the function substr was also named substr. I changed the parameter to a different name. Could it have something to do with that? ===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 **subs) { /* The following statement compiled fine under gcc and pcc */ *subs = ( (char *) realloc ( *subs,(unsigned) (numchar + 1))); } ========= -- -Satish. chittamu@cs.umass.edu -- The Theory of Objectivity: E = MC++