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

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.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

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
See more answers at brainly.com
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

So far, I've started with typedef struct gstring { char* data; size_t length; } gstring; // G for george, not the underwear!
Why are you looking to recreate the C string library? I mean, it's pretty battle tested as it is.
Or is this strictly a learning exercise?

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

It is a rite of passage :-D
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.
If only C supported operator overloading :( How am I going to print my gstrings though?
I guess I will be using the plain write() functions instead of the printf family :( but how will I do formatted input/output
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.

Not the answer you are looking for?

Search for more explanations.

Ask your own question