Is there a way to create a stream from a string? I know there is a way to do it using gnu's c library but I would rather not depend on that.
Is there a way to create a stream from a string? I know there is a way to do it using gnu's c library but I would rather not depend on that.
-Kernel SandersFried chicken for everybody!
Something similar to C++'s stringstream. What other information do you need?
-Kernel SandersFried chicken for everybody!
Are you reading from a file or stdin or is it just a buffer-full of characters?
If you're looking for something an append function for a string, go something like this.
. . . for a buffer of characters, for an append function. If, on the other hand, you're looking for something more along the lines of a snprintf()-style function, (other than snprintf() . . .), well, take a look at va_arg.Code:int append(char *str, size_t strsize, char *toappend) { if(str == NULL || toappend == NULL) return 1; if(strlen(str) + strlen(toappend) >= strsize) return 1; strncpy(str[strlen(str)-1], toappend, strlen(toappend)+1); return 0; }
EDIT: the code for something to append the contents of a filestream onto the string is much the same. Tip: use fgets.
Do as I say, not as I do . . .
Experimentation is the essence of programming. Just remember to make a backup first.
"I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF
Questions posted by these guidelines are more likely to be answered.
Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
Last edited by lruc; 03-23-2009 at 12:55 PM.
-Kernel SandersFried chicken for everybody!
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
You could get creative with strncpy() or strncat() since C does not provide an automatically-managed string type.