Created
October 6, 2013 14:28
-
-
Save maksadbek/6854747 to your computer and use it in GitHub Desktop.
String length without strlen, printf and sizeof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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