Date: Mon, 19 Oct 2009 20:24:49 -0700 From: Patrick Mahan <mahan@mahan.org> To: Gary Kline <kline@thought.org> Cc: FreeBSD Mailing List <freebsd-questions@freebsd.org> Subject: Re: need C help, passing char buffer[] by-value.... Message-ID: <4ADD2D81.4060002@mahan.org> In-Reply-To: <20091019222126.GB12488@thought.org> References: <20091019013337.GA9522@thought.org> <4ADBFDBA.6040702@pchotshots.com> <20091019170634.GA12371@thought.org> <4ADCAB4F.5040707@mahan.org> <20091019222126.GB12488@thought.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Gary Kline wrote: > On Mon, Oct 19, 2009 at 11:09:19AM -0700, Patrick Mahan wrote: >> See comments interspaced below - >> >> Gary, >> >> Let me restate your problem: You want to read through a file containing tags >> delimited by "<>" and to skip these tags if the user has run your command >> with >> the "-N" flag. >> >> In C any thing passed by address is "by reference". For a your static >> buffer >> of 1024 characters: you can pass it by reference as: >> >> skiptags(buf); /* passes in the starting address of the buffer */ >> skiptags(&buf[0]); /* passes in the starting address of the >> buffer */ >> skiptags(&buf[10]); /* passes int the starting address of the >> buffer >> at the 11th character position. */ >> >> Arrays and pointers are always by reference. Individual data types "int", >> "char", etc are by value unless passed in as a pointer. I think this is >> where >> your confusion is around. > > > You've got it exactly right, Patrick. There were no "C" classes in 1978--I > taught myself. Obviously, not that well because I have already dreaded > pointers. ---Well, usually. You are welcome, glad to help. [examples snipped] > > > Your examples help a lot! Everything works except when there are two or more > tags on one line such as: > > <BODY BGCOLOR="#FFFFFF" LINK="#00FFFF" VLINK="#006633"><FONT SIZE="4"> > > > I think I see where is your skiptags--pointer arithematic function--this can be > caught. Thanks much! > If I might make a suggestion. Make use of a case (switch) statement: switch(buf[c]) { case '<': /* start of tag, skip it if requested */ if (skiptags) c = skiptag(&buf[c]); ... default: /* handle normal stuff */ ... } Inside your while() statement. Good luck, Patrick
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4ADD2D81.4060002>