Write C Program to find length of string using pointer


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 string using pointer


  1. #include <stdio.h>
  2. #define MAX_SIZE 100 // Maximum size of the string
  3.  
  4. int main()
  5. {
  6. char text[MAX_SIZE];
  7. char * str = text;
  8. int count = 0;
  9.  
  10. // Inputtin string from user
  11. printf("Enter any string: ");
  12. gets(text);
  13.  
  14. // Iterating though last element of the string
  15. while(*(str++) != '\0') count++;
  16.  
  17. printf("Length of %s is: %d", text, count);
  18.  
  19. return 0;
  20. }
  21.  

Result

C language techstudy.org

     





Related Topics




Popular Posts