|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
customer getline functionI 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@... More majordomo info at http://vger.kernel.org/majordomo-info.html |
|
|
Re: customer getline functionLoL, 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@... > More majordomo info at http://vger.kernel.org/majordomo-info.html > - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@... More majordomo info at http://vger.kernel.org/majordomo-info.html |
| Free embeddable forum powered by Nabble | Forum Help |