/* 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:
#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:
0 comments:
Post a Comment