From owner-freebsd-questions@FreeBSD.ORG Tue Oct 20 03:24:55 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 71621106566C for ; Tue, 20 Oct 2009 03:24:55 +0000 (UTC) (envelope-from mahan@mahan.org) Received: from ns.mahan.org (ns.mahan.org [67.116.10.138]) by mx1.freebsd.org (Postfix) with ESMTP id 459068FC1B for ; Tue, 20 Oct 2009 03:24:55 +0000 (UTC) Received: from Gypsy.mahan.org (crowTrobot [67.116.10.140]) by ns.mahan.org (8.13.6/8.13.6) with ESMTP id n9K3WnjT076501; Mon, 19 Oct 2009 20:32:50 -0700 (PDT) (envelope-from mahan@mahan.org) Message-ID: <4ADD2D81.4060002@mahan.org> Date: Mon, 19 Oct 2009 20:24:49 -0700 From: Patrick Mahan User-Agent: Thunderbird 2.0.0.22 (X11/20090605) MIME-Version: 1.0 To: Gary Kline References: <20091019013337.GA9522@thought.org> <4ADBFDBA.6040702@pchotshots.com> <20091019170634.GA12371@thought.org> <4ADCAB4F.5040707@mahan.org> <20091019222126.GB12488@thought.org> In-Reply-To: <20091019222126.GB12488@thought.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Mailing List Subject: Re: need C help, passing char buffer[] by-value.... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Oct 2009 03:24:55 -0000 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: > > > > > 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