diff options
-rw-r--r-- | buf_misc.c | 10 | ||||
-rw-r--r-- | test_line.c | 14 |
2 files changed, 22 insertions, 2 deletions
@@ -86,12 +86,18 @@ int BufLine::add(char *string, int size) int BufLine::add(Buf *newdata) { buf->concat(newdata); - return -1; + return 0; } int BufLine::pop_line(char **val, int *size) { - + int idx; + if (1 == buf->findc('\n',&idx)) + { + printf("") + buf->popsubstring(4,val,size); + return 0; + } return -1; } diff --git a/test_line.c b/test_line.c index 3c3ccab..c001cc5 100644 --- a/test_line.c +++ b/test_line.c @@ -28,6 +28,14 @@ void error_is_good(int err) } #define E(X) error_is_good(X); +void print_s(char *str, int sz) +{ + int i = 0; + for (i=0;i<sz;i++) + printf("%c",str[i]); + fflush(stdout); +} + int main() { Buf *b1=NULL, *b2=NULL, *b3=NULL; @@ -58,6 +66,12 @@ int main() bline->add(b2); bline->print(); printf("\n"); printf("Get line\n"); + int sz=-1; + char *getline=NULL; + if (0==bline->pop_line(&getline,&sz)) + { + printf("[");print_s(getline,sz); printf("]\n"); + } printf("End test\n"); |