How to get a string length without string functions and loop in C

1 Answer

0 votes
#include <stdio.h> 

void _strlen(int len, char *s) 
{  
    if (s[len] == '\0') { 
        printf("%i", len);  
        return; 
    } 
      
    _strlen(len + 1, s); 
} 
 
int main(int argc, char **argv)
{ 
	char s[] = "c programming"; 
    
    _strlen(0, s); 
	
	printf("\n");
     
    return 0; 
}   
 
 
/*
run:
 
13
 
*/

 



answered Jan 14, 2019 by avibootz
edited Jan 14, 2019 by avibootz
...