Advertisement
AedenCak3

C program to count number of SPACES in string

Dec 8th, 2021
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     char a[100];
  6.     int space=0, i;
  7.  
  8.     printf("Write a sentence: \n");
  9.     gets(a);
  10.  
  11.     for(i=0; a[i]!='\0'; i++)
  12.     {
  13.         if( a[i]==' ' )
  14.         {
  15.             space+=1;
  16.         }
  17.     }
  18.  
  19.  
  20.     printf("The number of  spaces in the sentence are : %d",space);
  21.  
  22.  
  23.     return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement