Write a C program to compute length of the string without using library functiion

In this article we will learn how to compute length of the string without using library function in C language.

compute length of the string without using library functiion

Answers:

#include<stdio.h>
#include<conio.h>
int main()
{
  char str[20];
  int i;
  clrscr();
  printf("\n Enter the string:");
  gets(str);
  for(i=0;str[i]!='\0';i++)
  {
  printf("\n index number=%d",i);
  }
  printf("\n length of string:%d",i);
  getch();
  return 0;
}

#include<stdio.h>
#include<conio.h>
int main()
{
  char str[20];
  int i;
  clrscr();
  printf("\n Enter the string:");
  gets(str);
  for(i=0;str[i]!='\0';i++)
  {
  printf("\n index number=%d",i);
  }
  printf("\n length of string:%d",i);
  getch();
  return 0;
}

Note:

If you are unable to see whole code then open this page in desktop mode.

Post a Comment (0)
Previous Post Next Post