How to get a string length without string functions in C

1 Answer

0 votes
#include <stdio.h> 

int _strlen(char *s) {  
    int i = 0;
	
	while (s[i++] != '\0');
        
	return i - 1; 
} 

int main(int argc, char **argv)
{ 
	char s[10] = "abcde"; 
	
	printf("%d\n", _strlen(s)); 
     
    return 0; 
}   
 
 
/*
run:
 
5
 
*/

 



answered Jan 14, 2019 by avibootz
...