Skip to content

Instantly share code, notes, and snippets.

@maksadbek
Created October 6, 2013 14:28
Show Gist options
  • Save maksadbek/6854747 to your computer and use it in GitHub Desktop.
Save maksadbek/6854747 to your computer and use it in GitHub Desktop.
String length without strlen, printf and sizeof
#include <stdio.h>
typedef void (*fptr)(char* pString, int* pLen);
void istringlength(char* pString, int* pLen);
void pstringlength(char* pString, int* pLen);
fptr pFunc[2] = {istringlength, pstringlength};
void istringlength(char* pString, int* pLen) {
int nFactor = !(!(*pString));
*pLen += nFactor;
pFunc[!nFactor](pString+1, pLen);
return;
}
void pstringlength(char* pString, int* pLen) {
return;
}
int main () {
int nLen = 0;
istringlength("Hello World", &nLen);
printf("%d\n", nLen);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment