C Program Code for finding the string length without using string.h library function strlen, custom made strlen

Leave a Comment
 /* The following C Program Code contains a custom made strlen function, without using string.h it returns the length of the string. The user is prompted to enter the string of which the length is to be found. */

#include<stdio.h>
#include<conio.h>

int newstrlen(char*src)
//Function for string Length
{
int c=0;
while(*src!='\0')
{
++c;
src++;
}
return c;
}

int main()
{
  char s[100];
  int l;
  printf("\nEnter a string: ");
  gets(s);
  l=newstrlen(s);
  printf("\nString lenght is:%d",l);
  getch();
  return 0;
}


Screenshot:
C Program Code for finding the string length without using string.h library function strlen, custom made strlen

0 comments: