Write C program to find Length of the String by passing String/Character


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write C program to find Length of the String by passing String/Character


  1. #include<stdio.h>
  2.  
  3. //function declaration
  4. int stringLength(char *);
  5.  
  6. int main()
  7. {
  8. char text[100];
  9. int length;
  10.  
  11. printf("Enter text (max- 100 characters): ");
  12. scanf("%[^\n]s",text);
  13.  
  14. length = stringLength(text);
  15.  
  16. printf("Input text is: %s\n",text);
  17. printf("Length is: %d\n",length);
  18.  
  19. return 0;
  20. }
  21.  
  22.  
  23. int stringLength(char *str)
  24. {
  25. int len=0;
  26.  
  27. //calculating string length
  28. for(len=0; str[len]!='\0'; len++);
  29.  
  30. //returning len
  31. return len;
  32. }
  33.  

Result

C language

     





Related Topics




Popular Posts