logoISU  

CS256 - Principles of Structured Design

Fall 2021

Displaying ./code/cs256su21code/jun22/myStrlen.c

/*

recall that strlen returns the number of characters in a character array

recreate strlen below

*/
#include <stdio.h>

int myStrlen(char s[]);

int main()
{
	char str[256];

	printf("Enter a string: ");
	fgets(str, 256, stdin);

	int len = myStrlen(str);

	printf("Length of string is %d characters\n", len);

	return 0;
}

int myStrlen(char s[]){

	int len = 0;

	for(int i = 0; s[i] != '\0'; i++){
		len++;
	}

	return len;

}