100 Most Important C# Programs
45. Program to accept a string and find the length of the given string by using functions
Code:
# include <stdio.h>
# include <conio.h>
int getline(char str[]);
main( )
{
char str[80];
int length;
clrscr( );
printf(“ enter a string”);
length=getline(str);
printf(“length of the given string is
%d”,length);
getch ( );
}
int getline(char str[])
{
int i;
for(i=0;i<80&&((str[i]=getchar( ))!=’\n’);
i++);
if(str[i]= =’\n’)
str[i]=’\0’;
return i;
}