To write a C program to count the number of punctuation characters exists in a string using for loop.
1.Include necessary header files. 2.Define the main function. 3.Compile and run the program. 4.Run the program. 5.Display the output.
#include <stdio.h>
#include<string.h>
int main ()
{
int i, count = 0;
char str[100] ;
scanf("%[^\n]%*c",str);
for(i = 0; i < strlen(str); i++)
{
if(str[i] == '!' || str[i] == ',' || str[i] == ';' || str[i] == '.' || str[i] == '?' ||
str[i] == '-' || str[i] == '\'' || str[i] == '\"' || str[i] == ':')
{
count++;
}
}
printf("%d ",count);
return 0;
}
Thus the program to find the count of punctuations has been executed successfully.