Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!mit-eddie!mintaka!olivea!samsung!usc!sdd.hp.com!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Finding Available Length Of Strings... Message-ID: <14411@smoke.brl.mil> Date: 10 Nov 90 05:25:26 GMT References: <16752@hydra.gatech.EDU> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 18 In article <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?? What on earth do you mean? You don't pass strings to C functions; the best you can do is pass pointers to arrays containing chars. There is no way to determine in the called function where the end of the array allocation might be, given merely a pointer into it. Conventionally, C programming relies heavily on 0-terminated char arrays to represent character strings, but the 0 terminator value does not normally indicate anything about the valid extent of the array within which it lies. (For string LITERALS it does, but you can't count on being able to write into a string literal. Some systems put them into read-only memory.)