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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:17:25+00:00 2026-05-22T14:17:25+00:00

I need to translate some code from c++ to java, and I am not

  • 0

I need to translate some code from c++ to java, and I am not so sure how to deal with the ‘const char*’ operators. Check code below:

const char* handText;
const char* index = strchr(handText, '-');
char handCeil[4];
char handFloor[4];
strncpy(handCeil, handText, index - handText);
strcpy(handFloor, index + 1);

What I got is something like:

String handText;
String index = handText.substring(handText.indexOf('-'));
char handCeil[4];
char handFloor[4];

However, I don’t know what it means when you add integers (index + 1), or when you subtract (index – handText) strings in c++. Sorry if this is a stupid question, but I never learned how to program in c++, only in java. Thank you.

  • 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-05-22T14:17:26+00:00Added an answer on May 22, 2026 at 2:17 pm

    This

    strncpy(handCeil, handText, index - handText);
    strcpy(handFloor, index + 1);
    

    is equivalent to

    int index = handText.indexOf('-'); // I changed this for you
    handCeil = handText.substring(0, index+1);
    handFloor = handText.substring(index+1);
    

    So it splits the string by the ‘-‘ and puts the first part (including the ‘-‘ itself, I think) into handCeil and the remainder into handFloor.

    index - handText means this: index points to a specific character, handText points to the beginning of that string. If you subtract the two then you get the number of characters between those two pointers, or the array index of the first ‘-‘. strncpy copies n bytes, so if index points to the 3rd character it will copy 3 characters.
    index + 1 means point to the character 1 after the one pointed to by index.

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

Sidebar

Related Questions

I need to translate some code from Scheme to Common Lisp. Now, I have
For some reason, I need to translate the virtual address of the code section
I need help with translating some code from VB to C#. Public Function ToBase36(ByVal
I have never used ruby but need to translate this code to java. Can
I have a case where I need to translate (lookup) several values from the
I have a code that need to be translated from C to Cpp, and
The below code is from my other questions that I have asked here on
I need some help in bison grammar construction. From my another question: I'm trying
I've got some code originating from a DSL that needs to be translated for
[EDITED: I left the original question below, with some more context and code to

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.