In: Computer Science
Write a function int strlen(char s1[]) which returns the length of the char array s1.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.
Thank You!
===========================================================================
int strlen(char s1[]){
int index = 0;
while(s1[index]!='\0'){
index++;
}
return index;
}
====================================================================
Here is a C program to test the function
#include<stdio.h>
int strlen(char s1[]){
int index = 0;
while(s1[index]!='\0'){
index++;
}
return index;
}
int main(){
char s1[] = "Old Mac donald had a farm.";
printf("Length of \"%s\" is %d\n", s1,
strlen(s1));
return 0;
}
==============================================================