Pages

Monday, June 20, 2016

C program to demonstrate use of string length - strlen() function.

The strlen() function can be used to count total number of characters in a given string.




//This program will count total characters in given string.


#include<stdio.h>
#include<string.h>
int main()
{
  char str[20];
  int len=0;
  
  printf("Enter your string: ");
  gets(str);
  
  len=strlen(str);
  
  printf("Total characters in %s is :%d",str,len);
  return 0;
}
//Output of program
Enter your string: ahmedabad
Total characters in ahmedabad is :9


No comments:

Post a Comment