C Programming Tutorial

Advertisements

Write C program to count the length of a string



       #include<stdio.h>
       #include<conio.h>

       void main()
       {

              char str[50];
              int i,len=0;
              clrscr();

              printf("\nEnter any string : ");
              gets(str);
              
              for(i=0;str[i];i++)
                     len++;
              
              printf("\nLength of String : %d",len);

              getch();
    }

   Output : 

              Enter any string : My name is Kumar
              Total blank spaces : 16




Advertisement