Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!munnari.oz.au!uniwa!bilby.cs.uwa.oz.au!bilby!fraser From: fraser@bilby.cs.uwa.oz.au (Fraser Wilson) Newsgroups: comp.lang.c Subject: Re: Finding Available Length Of Strings... Message-ID: Date: 10 Nov 90 09:45:38 GMT References: <16752@hydra.gatech.EDU> Organization: Dept. Computer Science, University of Western Australia. Lines: 34 In <16752@hydra.gatech.EDU> gt4512c@prism.gatech.EDU (BRADBERRY,JOHN L) writes: >When passing strings to other functions, what is the BEST way to find >the bytes remaining in the formal string parameter (to prevent over- >writting the end while in the function)?? Does it involve using the >current starting address of the string parameter and calculating >(somehow) the DEFINED end?? The language supports no feature like this. All the function knows is that it has a pointer to char. If you want to know how much space is available, you have to do it yourself. eg #define LAST_CHARACTER '\1'; char s[32]; space(char *s) { int i; for(i=0;s[i]!=LAST_CHARACTER;i++); return i; } main() { s[31]=LAST_CHARACTER; printf("%i\n",space(s)); } >Thanks for any help here... You're welcome. Hope it does. Fraser.