need C help, passing char buffer by-value....
mahan at mahan.org
Tue Oct 20 03:24:55 UTC 2009
Gary Kline wrote:
> On Mon, Oct 19, 2009 at 11:09:19AM -0700, Patrick Mahan wrote:
>> See comments interspaced below -
>> 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
>> the "-N" flag.
>> In C any thing passed by address is "by reference". For a your static
>> of 1024 characters: you can pass it by reference as:
>> skiptags(buf); /* passes in the starting address of the buffer */
>> skiptags(&buf); /* passes in the starting address of the
>> buffer */
>> skiptags(&buf); /* passes int the starting address of the
>> 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
>> 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.
> 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:
case '<': /* start of tag, skip it if requested */
if (skiptags) c = skiptag(&buf[c]);
default: /* handle normal stuff */
Inside your while() statement.
More information about the freebsd-questions