From owner-freebsd-questions@FreeBSD.ORG Mon Oct 19 05:48:41 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 B581B106566C for ; Mon, 19 Oct 2009 05:48:41 +0000 (UTC) (envelope-from bmettee@pchotshots.com) Received: from mail.pchotshots.com (ns1.pchotshots.com [12.172.123.235]) by mx1.freebsd.org (Postfix) with SMTP id 7A8C58FC28 for ; Mon, 19 Oct 2009 05:48:41 +0000 (UTC) Received: (qmail 45034 invoked by uid 89); 19 Oct 2009 05:50:18 -0000 Received: from unknown (HELO ?12.172.123.228?) (bmettee@pchotshots.com@12.172.123.228) by mail.pchotshots.com with SMTP; 19 Oct 2009 05:50:18 -0000 Message-ID: <4ADBFDBA.6040702@pchotshots.com> Date: Mon, 19 Oct 2009 01:48:42 -0400 From: Brad Mettee User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Gary Kline , FreeBSD Mailing List References: <20091019013337.GA9522@thought.org> In-Reply-To: <20091019013337.GA9522@thought.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: 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: Mon, 19 Oct 2009 05:48:41 -0000 Gary Kline wrote: > Guys, > > maybe this can't be done reading in a file with fgets(buffer[128], fp), > then calling skiptags(), conditionally, to while () past ',' and '>'. > > I know I need to calll skipTags with its address, skipTags(&buffer);, but then how to i > handle the variable "s" in skipTags? Anybody? > > > > > // redo, skip TAGS > skipTags((char *)&s) > { > if (*s == '<') > { > while (*s != '>') > { > s++; > } > s++; > } > } > Your function may not work exactly as you think it will. Your basic idea runs on the assumption that the tag will never be broken during the file read. It's possible that you'll read "some datamore data here", or some variation thereof. If you know for a fact that the string you read in will always be complete, then what's below should work fine: // where *s is the address of a string to be parsed // maxlen represents the maximum number of chars potentially in the string and is not zero based (ie: maxlen 256 = char positions 0-255) // *curpos is the current position of the pointer (this prevents bounds errors) skipTags(char *s, long maxlen, long *curpos) { if (*s == '<') { while (*s != '>' && && *s && *curpos < maxlen) { s++; (*curpos)++; } if (*curpos < maxlen) { s++; (*curpos)++; } } } When you read in the next line of the file, reset curpos to zero, set maxlen to number of bytes read. As you process each char after the function is called, you'll need to increment curpos as well. Depending on the size of the files you are reading, you may be able to read the entire file into memory at once and avoid any possible TAG splitting. If you explain exactly what you're trying to accomplish, we may be able to come up with an easier/cleaner solution. (warning: none of the above code is tested, but in concept it should work ok)