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 7793341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:27:23+00:00 2026-06-01T22:27:23+00:00

My program reduce expression to one value. I have a problem with changing char

  • 0

My program reduce expression to one value.
I have a problem with changing “char sign” as a character of action. Could you show me some simple solution or idea how to do it?

I tried:

(tab[i]-'0') 'sign' (tab[i+1]-'0'); 

This is the full code:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{

    char* tab = "12+";
    int b = sizeof (tab);
    char* tmp = new char[b] ;
    tmp [b-1] = '\0';

    int k = b/3;

    for(int i=0; i<k; i++){

            if(isdigit(tab[i]) && isdigit(tab[i+1]) ){

               if(tab[i+2]=='+' || tab[i+2]=='-' || tab[i+2]=='*'){
                  char sign = tab[i+2];

                  int n = (tab[i]-'0') + (tab[i+1]-'0');  //here is a problem, i want to replice + as a char sign which will be recognized

                  tmp[i] = n+'0';
               }
               else goto LAB;
            }

            else if (isdigit(tab[i]) && isdigit(tab[i+2])){


            }
            else if (isdigit(tab[i+1]) && isdigit(tab[i+2])){

            }


            else 
            LAB:
            tmp[i]= tab[i];

    }

    cout<<"Import "<<tmp[0]-'0'<<endl;        


    system("PAUSE");
    return EXIT_SUCCESS;
}
  • 1 1 Answer
  • 0 Views
  • 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-06-01T22:27:25+00:00Added an answer on June 1, 2026 at 10:27 pm

    You cannot replace an operator, or function name with a symbol which is given by user, because compiler has to know which function should be called and there is no mechanism to convert a ‘+’ character to operator+(int, int) call embedded in a language. You have to write it by yourself.

    The simplest solution is to write explicitly every operator you want to support:

    int n;
    switch(tab[i+2]){
        case '+':
            n = (tab[i]-'0') + (tab[i+1]-'0');
            break;
        case '-':
            n = (tab[i]-'0') - (tab[i+1]-'0');
            break;
        // etc...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Map reduce/Hadoop is one of the framework/program that s used for distributed systems. What
I'm implementing a classical map-reduce program in which I have a parent that spwans
I am writing a program to do integer factorization and have to reduce a
My program needs to know when a user ejects cd disc. Is there some
My program does some network activity in a background thread. Before starting, it pops
For my program, I am trying to assist the user, and reduce his or
I have a Python program that processes fairly large NumPy arrays (in the hundreds
I have read that it is a good idea to give a 3D program
So I have this MFC dialog program I am working with. The dialogs are
My program uses PyOpenGL (so it's Python) with psyco. I have around 21,000 line

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.