linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* customer getline function
@ 2006-10-30  5:37 Steve McDaniel
  2006-10-30  5:47 ` Steve McDaniel
  0 siblings, 1 reply; 2+ messages in thread
From: Steve McDaniel @ 2006-10-30  5:37 UTC (permalink / raw)
  To: linux-c-programming

I wrote a getBufferLine function that will read a line at a time from a
buffer. Just returns everything til it hits '\n', then will move to the
next.It works on small buffers, but seems to segfault on anything large.
Trying to figure out how pointers work in C, any pointers would help.

here is an example to use this function....
while ((c = getBufferLine(&ptr,buf,BufLen)) != NULL)
	printf("%s", c);

unsigned char* buffer_line_get(unsigned char** lineptr, unsigned char*
buffer, int size)
{
        static int index;
        unsigned char* c;

        if((size - index) == 0)
                return NULL;

        if (lineptr == NULL)
                *lineptr = c = buffer;
        else
                *lineptr = ((c = buffer) + index + 1);

        index = 0;
        while ((lineptr[index++] != '\n') && (index < size));

        lineptr+=index;
        *(buffer + index) = 0;
        return c;
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: customer getline function
  2006-10-30  5:37 customer getline function Steve McDaniel
@ 2006-10-30  5:47 ` Steve McDaniel
  0 siblings, 0 replies; 2+ messages in thread
From: Steve McDaniel @ 2006-10-30  5:47 UTC (permalink / raw)
  To: linux-c-programming

LoL, I guess I should really read over things before sending out
emails...it is actually supposed to be custom.....and
the function declaration is supposed to be bufferGetLine

Steve McDaniel wrote:
> I wrote a getBufferLine function that will read a line at a time from a
> buffer. Just returns everything til it hits '\n', then will move to the
> next.It works on small buffers, but seems to segfault on anything large.
> Trying to figure out how pointers work in C, any pointers would help.
> 
> here is an example to use this function....
> while ((c = getBufferLine(&ptr,buf,BufLen)) != NULL)
> 	printf("%s", c);
> 
> unsigned char* buffer_line_get(unsigned char** lineptr, unsigned char*
> buffer, int size)
> {
>         static int index;
>         unsigned char* c;
> 
>         if((size - index) == 0)
>                 return NULL;
> 
>         if (lineptr == NULL)
>                 *lineptr = c = buffer;
>         else
>                 *lineptr = ((c = buffer) + index + 1);
> 
>         index = 0;
>         while ((lineptr[index++] != '\n') && (index < size));
> 
>         lineptr+=index;
>         *(buffer + index) = 0;
>         return c;
> }
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-10-30  5:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-30  5:37 customer getline function Steve McDaniel
2006-10-30  5:47 ` Steve McDaniel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).