I have written a small library for manipulating strings in C. It is very small (~300 LOC), and it's used are limited so far, but it has found great application in many of my programs for things such as reading numbers from strings and generating output filenames. I hope you find it useful.
Feel free to contribute code, I'd love to see this a more complete and useful library. Although, you will have to ask to have your permissions raised so you can, which I'd rather not have to, but whatever.
Not to be a dick, but the code is piss-poor quality and has many serious problems (memory leaks everywhere, not using standard library functions for copying, runtime complexity class of some functions is higher than it should be).
Name:
Anonymous2012-01-29 22:16
>>6
Then stop complaining and contribute some `high quality' code.
>>7
It's not worth it. If this is the kind of functions and programming style you'd like to use, I'd recommend looking into another language. One with automatic memory management, preferably.
Name:
Anonymous2012-01-29 22:23
Python has really good string manipulation capabilities.
This little module is about 30 years behind the times. Why are C programmers repeatedly reinventing these shitty little things, year after year?
It is because in the C culture, programmers who grow out of this are ashamed of this crap and do not pass it down to their successors, so no cross-generation learning takes place and the same crud is reinvented.
Say, I need a collection of things. Hey, I know:
struct list { struct list *next, *prev; void *item; }
Name:
Anonymous2012-01-31 2:12
Holy crap, is this guy for real???
/*
* Creates a copy of the original
* string without destroying data
*/
char *str_dup(char *str)
{
char *result;
int len;
if (!str){
result = malloc(1);
*result = 0;
return result;
}
len = strlen(str);
result = malloc(len);
memcpy(result, str, len);
return result;
}
And y'all have been down on the guy for using null terminated strings? No, he isn't: look again. :)