https://github.com/akashnag/c-candy

A string and data structures library for C

https://github.com/akashnag/c-candy

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

c dynamic-array library list stack string string-iteration tuple
Last synced: 5 months ago · JSON representation

Repository

A string and data structures library for C

Basic Info
  • Host: GitHub
  • Owner: akashnag
  • License: gpl-2.0
  • Language: C
  • Default Branch: master
  • Homepage:
  • Size: 48.8 KB
Statistics
  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
c dynamic-array library list stack string string-iteration tuple
Created over 4 years ago · Last pushed over 4 years ago
Metadata Files
Readme License

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

GitHub Events

Total
Last Year