How to implement the strlen function in C

1 Answer

0 votes
#include <stdio.h>

size_t strlen(const char* s) {
	// find length of s
	const char* p;

	for (p = s; *p != '\0'; p++)
		;
	return p - s;
}

int main(void) {
	char str[] = "c programming";

	printf("%zu", strlen(str));

	return 0;
}




/*
run:
    
13
    
*/

 



answered Dec 18, 2022 by avibootz

Related questions

3 answers 465 views
1 answer 204 views
204 views asked Sep 20, 2021 by avibootz
2 answers 427 views
3 answers 434 views
...