Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  count characters
Language: C/C++
Code:
#include<stdio.h>
#include<string.h>
int main()
{
int i,ch,count=0,flag=0;
char str[100];
printf("Enter the string");
scanf("%s",str);
ch=strlen(str);
for(i=0;str[i] !='\0';i++)
{
if((str[i]>='a' && str[i]<='z')|| (str[i]>='A' && str[i]<='Z') || str[i]==' ')
{
count++;
flag=1;
}
else
{
printf("Invalid Input");
break;
}
}
if(flag==1)
printf("%d",count);
return 0;
}
Comments: