Path: utzoo!attcan!uunet!seismo!dimacs.rutgers.edu!mips!pacbell.com!decwrl!mcnc!rti!dg-rtp!gamecock!hagins From: hagins@gamecock.rtp.dg.com (Jody Hagins) Newsgroups: comp.lang.c Subject: Re: Finding Available Length Of Strings... Message-ID: <1990Nov10.175308.21912@dg-rtp.dg.com> Date: 10 Nov 90 17:53:08 GMT References: <16752@hydra.gatech.EDU> <16758@hydra.gatech.EDU> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Reply-To: hagins@gamecock.rtp.dg.com (Jody Hagins) Organization: Data General Corporation, Research Triangle Park, NC Lines: 93 In article <16758@hydra.gatech.EDU>, gt4512c@prism.gatech.EDU (BRADBERRY,JOHN L) writes: |> Just a note of clarification here...I am talking about a character array |> and I am looking for a solution (not the obvious '...add another length |> parameter')...I would like the function to be able to 'figure it out!' |> |> Thanks again! |> |> -- |> John L. Bradberry |Georgia Tech Research Inst|uucp:..!prism!gt4512c |> Scientific Concepts Inc. |Microwaves and Antenna Lab|Int : gt4512c@prism |> 2359 Windy Hill Rd. 201-J|404 528-5325 (GTRI) |GTRI:jbrad@msd.gatech. |> Marietta, Ga. 30067 |404 438-4181 (SCI) |'...is this thing on..?' There are several ways to do this. 1. typedef struct { int size; /* Alternatively, this could be the last address */ char * s; } string_t; void strinit(string_t *sp, char *cp, int size) { sp->s = cp; sp->size = size; } main() { char some_var[SOME_SIZE]; string_t string; strinit(&string, some_var, SOME_SIZE); ... } Whenever you want to use the C string functions, send string->s. If you want to use your own, send &string and access both start address and the length. 2. #define DEFINED_EOS ((char)1) /* Any char you can guarantee not in a string */ #define FILL_CHAR '\0' /* Any char except DEFINED_EOS */ char *strinit(char *s, int size) { int i; for(i=0; i