Function argument question

Art Berggreen ART at acc.ARPA
Fri Aug 9 09:56:50 AEST 1985



> 	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 at ACC.ARPA>

------



More information about the Comp.lang.c mailing list