Skip to content

Instantly share code, notes, and snippets.

@mikhailramalho
Created January 12, 2016 16:16
Show Gist options
  • Save mikhailramalho/18f8174f1246fe6d6785 to your computer and use it in GitHub Desktop.
Save mikhailramalho/18f8174f1246fe6d6785 to your computer and use it in GitHub Desktop.
Pointer arithmetic
#include <assert.h>
unsigned int my_strlen(const char* s)
{
const char *eos = s;
while (*eos++);
return (int) (eos - s - 1);
}
int main()
{
const char* str = "Test!";
assert(my_strlen(str) == 5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment