anonymous
  • anonymous
I want to write my own C string library. What should I do? I want it to be able to do everything the C standard library functions can do, but quicker and safer. It needs to be portable and easy to use and bug-free as well
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
So far, I've started with typedef struct gstring { char* data; size_t length; } gstring; // G for george, not the underwear!
farmdawgnation
  • farmdawgnation
Why are you looking to recreate the C string library? I mean, it's pretty battle tested as it is.
farmdawgnation
  • farmdawgnation
Or is this strictly a learning exercise?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
It is a rite of passage :-D
anonymous
  • anonymous
The next thing I'd do is add constructors and start overloading operators. Assignment operators, concatentation with +, conversion operator to char*, and stream insertion and extraction operators.
anonymous
  • anonymous
If only C supported operator overloading :( How am I going to print my gstrings though?
anonymous
  • anonymous
I guess I will be using the plain write() functions instead of the printf family :( but how will I do formatted input/output
anonymous
  • anonymous
Ah, C, not C++ - my mistake ;) So, in lieu of operators, you'll need standalone functions for concatenation and similar. For printing, you could just printf("String: %s", myGString.data), or write a new function printfgstring that can take a gstring as its sole argument, or even decomposes a variable argument list and gets the c-string out of your gstring struct.

Looking for something else?

Not the answer you are looking for? Search for more explanations.