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

  • Home
  • SEARCH
  • 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 7809405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:25:40+00:00 2026-06-02T03:25:40+00:00

I have problem with giving new char valure to array. I don’t know why

  • 0

I have problem with giving new char valure to array. I don’t know why I get sign “<” even when n is 12? My program should change expression int char* tab = "93+" to one value in this case 12.

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


if(isdigit(tab[i]) && isdigit(tab[i+1]) ){
               int n;             
               if(tab[i+2]=='+' || tab[i+2]=='-' || tab[i+2]=='*'){

                  switch(tab[i+2]){
                    case '+':   
                    n = (tab[i]-'0') + (tab[i+1]-'0');

                    break;

                    case '-':
                    n = (tab[i]-'0') - (tab[i+1]-'0');
                    break;

                    case '*':
                    n = (tab[i]-'0') * (tab[i+1]-'0');
                    break;
                  }
                  tmp[i] = n+'0'; // I should have 12 but I get <
               }

               else if (tab[i+2]!='+' || tab[i+2]!='-' || tab[i+2]!='*'){
                     goto LAB;
               }
}
  • 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-02T03:25:41+00:00Added an answer on June 2, 2026 at 3:25 am

    The problem is in this line:

    tmp[i] = n+'0'; // I should have 12 but I get <
    

    n is 12, but 12 + ‘0’ != ’12’, since ’12’ isn’t a character. You’re putting into tmp[i] the char whose ascii value is 12 more than ‘0’, which is ‘<‘.
    I believe declaring (and treating) tmp as an int would be better for your purposes.

    Also note that sizeof (tab) is the same as sizeof (char *), and not sizeof ("93+"), so you’re likely to always get b==4 (in 32-bit machines).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be simple. Yet, it's giving me Hell. Problem I have compiled the
I have a problem. This code is not giving the results it should. It
I seem to stumble on problem after problem giving my entities behaviour. I have
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I'm quite new in Hibernate, and I'm hurting a problem giving me huge headaches
I have a helper function that takes an unsigned char array of a fixed
I have a problem in giving Ajax functionality to a hyperlink. I have files
friends, i have problem in calling notifydatasetchanged(); it is giving me exception source not
i have a simple problem but it is giving me a big problem im
I'm new to Obj-C, and I have a little problem here. I'm trying insert

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.