Using pointers, find the length of the given string.
Program : -
#include<stdio.h>
#include<conio.h>
void main()
{
char string[100];
char *p;
int length=0;
clrscr();
printf("|*******************|");
printf("\nwww.flintgroups.com\n");
printf("|*******************|\n");
printf("Enter a string : \n");
gets(string);
for(p=string;*p!='\0';p++);
length=p-string;
printf("\nLength of string is : %d",length);
getch();
}
The sample output for this program is as shown below.
Program : -
#include<stdio.h>
#include<conio.h>
void main()
{
char string[100];
char *p;
int length=0;
clrscr();
printf("|*******************|");
printf("\nwww.flintgroups.com\n");
printf("|*******************|\n");
printf("Enter a string : \n");
gets(string);
for(p=string;*p!='\0';p++);
length=p-string;
printf("\nLength of string is : %d",length);
getch();
}
The sample output for this program is as shown below.

This comment has been removed by the author.
ReplyDelete