Logo

Programming-Idioms

History of Idiom 169 > diff from v74 to v75

Edit summary for version 75 by georgn:
[C] The idiom was asking to assign string length to another variable - not provide an implementation of strlen

Version 74

2019-12-01, 11:46:00

Version 75

2020-04-28, 22:06:37

Idiom #169 String length

Assign to integer n the number of characters of string s.

This can be different from the number of bytes of s.

Illustration

Idiom #169 String length

Assign to integer n the number of characters of string s.

This can be different from the number of bytes of s.

Illustration
Extra Keywords
size characters chars number runes
Extra Keywords
size characters chars number runes
Imports
#include <stdlib.h>
Imports
#include <string.h>
Code
size_t	ft_strlen(const char *str)
{
	int	count;

	count = 0;
	while (str[count])
		count++;
	return (count);
}
Code
size_t n = strlen(s);
Comments bubble
Assumes s is actually a string
Origin
https://github.com/iiskakov/42-libft/blob/master/libft.h
Origin
https://github.com/iiskakov/42-libft/blob/master/libft.h