1) Find length of string in c language using pointer
2) Find length of string in c language without using pointer
#include <stdio.h>
int main()
{
char arr[100], *p;
int length = 0;
printf("Enter String : ");
gets(arr);
p = arr;
while( *( p + length ) )
length++;
printf("String Length = %d", length);
return 0;
}
#include <stdio.h>
int main()
{
char str[100];
int i, length = 0;
printf("Enter String : ");
gets(str);
for (i = 0; str[i] != '\0'; i++)
{
length++;
}
printf("String Length = %d", length);
return 0;
}
0 comments :
Post a Comment