Count input length without spaces, periods, or commas Given a line of text as input, output the number of characters excluding spaces, periods, or commas. You may assume that the input string will not exceed 50 characters.
Ex: If the input is:
Listen, Mr. Jones, calm down.
the output is:
21
Note: Account for all characters that aren't spaces, periods, or commas (Ex: "r", "2", "!").
Can I get this in C programming please?

Respuesta :

Answer:

This program is implemented in C++ using dev C++.  The solution of this answer along with running code is given below in explanation section.

Explanation:

#include <iostream>

#include<string>

using namespace std;

int main()

{

   string str;

   

cout<<"Enter String \n";

 

getline(cin,str);/* getLine() function get the complete lines, however, if you are getting string without this function, you may lose date after space*/

 

   //cin>>str;

 

   int count = 0;// count the number of characeter

   for (int i = 1; i <= str.size(); i++)//go through one by one character

   {

     

   

    if ((str[i]!=32)&&(str[i]!=44)&&(str[i]!=46))//do not count  period, comma or space

 {

           ++ count;//count the number of character

       }

   }

   cout << "Number of characters are  = "; //display

cout << count;// total number of character in string.

   return 0;

}

}

Answer:

user_text = input()

import re

string = ( "listen, Mr. Jones, calm down.")

print(len(re.sub(r'[,.\s]+', '', string)))

Explanation: