Skip to content

Instantly share code, notes, and snippets.

@erickguan
Created March 25, 2019 19:37
Show Gist options
  • Save erickguan/84a0c25e80d60a27592487e8a08346f6 to your computer and use it in GitHub Desktop.
Save erickguan/84a0c25e80d60a27592487e8a08346f6 to your computer and use it in GitHub Desktop.
An example C buffer implementation
int convert_blank_to_quote(const char* source, char* dest, int64_t buffer_size)
{
--buffer_size; // the last character would be '\0'
if (buffer_size <= 0) {
return -1; // illegal argument: buffer size too small
}
int64_t i = 0;
for (const char* p = source; *p != '\0' && i < buffer_size; ++p, ++i) {
*(dest + i) = p == ' ' ? '@' : *p;
}
*(dest + buffer_size) = '\0';
return buffer_size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment