Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 561379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:26:38+00:00 2026-05-13T12:26:38+00:00

I’m trying to write a function to detect separators as defined by an assignment

  • 0

I’m trying to write a function to detect separators as defined by an assignment and I know it is not good programming style to

#define EXCLAMATION_POINT 33, but to instead do #define EXCLAMATION_POINT '!'

This is my code:

#include <iostream>
#include <ostream>
using namespace std;
#define PERIOD '.'
#define QUESTION_MARK '?'
#define EXCLAMATION_POINT '!'
#define COMMA ','
#define COLON ':'
#define SEMICOLON ';'

inline bool IsSeparator(int x) 
{
    if (isspace(x) || 
        x == PERIOD || 
        x == QUESTION_MARK ||
        x == EXCLAMATION_POINT ||
        x == COMMA ||
        x == COLON || 
        x == SEMICOLON) {
        return true;
    }
    else {
        return false;
    }
}

int main (int argc, char * const argv[]) {
    int input;
    cout << "Enter characters: \n";
    input = cin.get();
    if (!IsSeparator(input))
        cout << "true";
    else {
        cout << "false";
    }
    return 0;
}

But in my IsSeparator(), how do I typecast that int to a char to be compared to ‘!’. I thought if I did something like (char)EXCLAMATION_POINT that would work, but it does not and the value is left at an int. What am I doing wrong here? Thanks!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:26:38+00:00Added an answer on May 13, 2026 at 12:26 pm

    You don’t need any cast, but:

    if (!IsSeparator(input))
    

    should be:

    if (IsSeparator(input))
    

    Also, your prompt:

    cout << "Enter characters: \n";
    

    implies you can enter multiple characters. So you can, but cin.get() will only read one.

    Regarding giving symbolic names to things. Suppose you are parsing a file where the separator is a colon. It then makes sense to say:

    const char SEPARATOR = ':';
    

    because you can then change it when the file format changes, for example to:

    const char SEPARATOR = '|';
    

    but it doesn’t normally make sense to give your own names to the members of the ASCII (or whatever) character set.

    In your code, it might make sense to create an array of separators (I’m not showing all the ones you use for my ease of typing):

    const char SEPARATORS[] = {':', '|', '!', 0 };
    

    and then have your validation function iterate over the array. Note in this case, the array could also have been expressed as a string literal:

    const char * const SEPARATORS = ":|!";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.