https://github.com/akashnag/c-candy
A string and data structures library for C
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (5.2%) to scientific vocabulary
Keywords
Repository
A string and data structures library for C
Basic Info
Statistics
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
c-candy
C-Candy is a string and data structures library for C.
Currently only 4 types are defined. Please refer to the concerned documentation page for the API, from the table below.
Documentation
| Type | Description | Documentation | |-|-|-| | STRING | Mutable string | STRING | | STR_ITERATOR | String iterator | STR_ITERATOR | | LIST | Dynamic array | LIST | | TUPLE | Tuple | TUPLE | | STACK | Linked stack | STACK |
Examples
Longest word in a sentence
Using plain C:
```c
include
include
include
char* getlongestword(const char *s) { int i, lwstart, lwend;
int n = strlen(s);
int ls = -1;
int lw_len = 0;
for(i = 0; i <= n; ++i)
{
if(s[i] == ' ' || s[i] == '\0')
{
if(i-ls-1 > lw_len)
{
lw_start = ls + 1;
lw_end = i;
lw_len = lw_end - lw_start;
}
ls = i;
}
}
char *lw = (char*)calloc(lw_len + 1, sizeof(char));
if(lw == NULL) return NULL;
for(i = lw_start; i < lw_end; ++i)
lw[i-lw_start] = s[i];
lw[lw_end-lw_start] = '\0';
return lw;
}
int main(int argc, char **argv) { const char *s = "The quick brown fox jumps over the lazy dog"; char *lw = getlongestword(s);
printf("Longest word = %s\n", lw);
return 0;
} ```
Using C-Candy:
```c
include
include
include
STRING* getlongestword(STRING *s) { int i, n;
int lwi = 0;
STRING **parts = str_split_whitespace(s, 100, &n);
if(n < 1) return NULL;
for(i = 1; i < n; ++i)
if(str_len(parts[i]) > str_len(parts[lwi]))
lwi = i;
STRING *lw = str_copy(parts[lwi]);
for(i = 0; i < n; ++i) str_dump(parts[i]);
free(parts);
return lw;
}
int main(int argc, char **argv) { STRING *s = string("The quick brown fox jumps over the lazy dog"); STRING *lw = getlongestword(s);
printf("Longest word = %s\n", cstr(lw));
str_dump_multi(s, lw);
return 0;
} ```
Owner
- Name: Akash Nag
- Login: akashnag
- Kind: user
- Location: Kolkata, India
- Twitter: AkashNagCS
- Repositories: 2
- Profile: https://github.com/akashnag