Without using the strlen():-
#include<stdio.h>
void main()
{
char a[20],i;
printf("enter the string:-");
scanf("%s",a);
for(i=0; a[i]!='\0'; ++i);
printf("length of the string: %d",i);
}
enter the string:-abc
length of the string:3
Using the strlen():-
#include<stdio.h>
#include<string.h>
void main()
{
int len;
char a[20];
printf("enter the string:-");
gets(a);
len=strlen(a);
printf("%d",len);
}
#include<stdio.h>
printf("enter the string:-");
length of the string:3
Using the strlen():-
#include<stdio.h>
#include<string.h>
void main()
{
int len;
char a[20];
printf("enter the string:-");
gets(a);
len=strlen(a);
printf("%d",len);
}
No comments :
Post a Comment