C Programming Tutorial

Advertisements

Write C program to count total number of blank spaces in a string



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

       void main()
       {

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

              printf("\nEnter any string : ");
              gets(str);
              
              for(i=0;str[i];i++)
                     if(str[i] == ' ')
                           count++;
              
              printf("\nTotal blank spaces : %d",count);

              getch();
    }

   Output : 

              Enter any string : My name is Kumar.
              Total blank spaces : 3




Advertisement