PAWKA@nosc-tecr.ARPA (Pawka) (08/08/85)
I have a quick question which should be easy for some "C" expert out there, I want to write a function which takes a character pointer as an input, processes the string, returns an integer AND! updates the string pointer in the process. Thanks, Mike Pawka PAWKA@NOSC-TECR.ARPA ------
gwyn@BRL.ARPA (VLD/VMB) (08/09/85)
> ... a function which takes a character pointer as an input, processes > the string, returns and integer AND! updates the string pointer in > the process. Obviously this cannot be done precisely as stated. You will have to pass a POINTER to a character pointer, if you want to modify the character pointer. E.g. int function( char **strp );
ART@acc.ARPA (Art Berggreen) (08/09/85)
> I have a quick question which should be easy for some "C" expert > out there, I want to write a function which takes a character pointer > as an input, processes the string, returns an integer AND! updates the > string pointer in the process. Thanks, One way to approach this is to pass a pointer to the char pointer in the function call. You can then update the char pointer before the function returns, and the return value of the function can be the integer. e.g. int cnt; char *cp; . . cnt = foo(&cp); . . } foo(acp) char **acp; { int val; char *cp = *acp; /* use cp to ref string */ . *acp += val; . return(val); } "Art Berggreen"<Art@ACC.ARPA> ------
friesen@psivax.UUCP (Stanley Friesen) (08/12/85)
In article <555@brl-tgr.ARPA> ART@acc.ARPA (Art Berggreen) writes: > > >One way to approach this is to pass a pointer to the char pointer in >the function call. You can then update the char pointer before the >function returns, and the return value of the function can be the >integer. > Another approach is to pass the function a second argument, a pointer to an int for the numeric result and actually *return* the new char pointer. This avoids using a pointer to a pointer. -- Sarima (Stanley Friesen) {trwrb|allegra|cbosgd|hplabs|ihnp4|aero!uscvax!akgua}!sdcrdcf!psivax!friesen or {ttdica|quad1|bellcore|scgvaxd}!psivax!friesen