Ask your own question, for FREE!
Computer Science 9 Online
OpenStudy (anonymous):

I'm thinking of writing my own C string library. Any ideas?

OpenStudy (anonymous):

What are the different ways to implement strings (besides the default way C does it i.e. a sequence of characters with a nul character at the end, no nul characters in between, etc.)? Which way should I use? What functions should I include in my string library? How do I design a good library?

OpenStudy (anonymous):

Why do I need to write my own string library in C? Simply as an exercise :-D I'll learn a lot and I might end up with something useful as a result.

OpenStudy (anonymous):

I advise you to look into cs50 library provided somewhere in the cs50 page (I will search for the link later, if you wish). They implement the string using malloc, for resizing and some other cool stuff, but it's prone to memory leaks, so always remember calling free() :-)

OpenStudy (anonymous):

https://manual.cs50.net/CS50_Library Here is to documentation and how to get it.

OpenStudy (anonymous):

the* documentation

OpenStudy (anonymous):

I'm checking out http://bstring.sourceforge.net/

OpenStudy (anonymous):

@bmp you mean the getstring() function?

OpenStudy (anonymous):

all the CS50 C library does it implement a few functions which translate user input into given datatypes like int, double, and string; they haven't really implemented their own strings all they've done is abstract away the default 'char*' representation of strings in C with a typedef

OpenStudy (anonymous):

Oh, I am sorry. I thought you meant that. Hmm, I will think more about some string abstraction possible in C.

OpenStudy (anonymous):

String objects are a special type of container, specifically designed to operate with sequences of characters. Unlike traditional c-strings, which are mere sequences of characters in a memory array, C++ string objects belong to a class with many built-in features to operate with strings in a more intuitive way and with some additional useful features common to C++ containers.

OpenStudy (anonymous):

Too bad C doesn't have classes, so I will have to resort to structs :-P

OpenStudy (llib_xoc):

It might be fun to implement a string library where each string is represented by a length/pointer pair. When the length is available, you no longer need the NUL terminator character, and it becomes possible to store a NUL char (possibly input from some binary file) in a string and use the library on it.

OpenStudy (llib_xoc):

I just noticed that Google's go language has a length, pointer string type. Here's the equivalent C structure: struct __go_string { const unsigned char *__data; int __length; }; It's also a cool language. More info here: http://gcc.gnu.org/onlinedocs/gcc-4.6.1/gccgo/

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!