Page

C Program To Count The Character and Spaces in String

#include<stdio.h>
#include<conio.h>
void main()
{
     int c=0,s=0,i;
     char ch,str[125];
     clrscr();
     printf("Enter a string :");
     gets(str);
     printf("\n\nEntered String is \" %s \" \n",str);
     for(i=0;str[i]!='\0';i++)
     {
     if(str[i]==' ')
s++;
     c=i+1;
     }
     printf("\n\nTotal Characters : %d",c);
     printf("\nTotal Spaces     : %d",s);
     getch();
}

No comments:

Post a Comment