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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:40:24+00:00 2026-06-11T14:40:24+00:00

I have a character pointer that points the begining of a string and an

  • 0

I have a character pointer that points the begining of a string and an index less than the length of the string. Now I want to create a pointer to point a substring of original string from the begining to the index or a substring with above constraints. Please help me to find a way to get it done. Here is a bit of the code:

char* ch="323+465";//this is the original string
int index=2;  //this is the index upto which I wish to create a substring, 
              // in java, it would have been ch.substring(0,3), if ch were a String

Thanks in advance.

  • 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-11T14:40:26+00:00Added an answer on June 11, 2026 at 2:40 pm

    Make a copy of a suitable number of characters:

    char * substr = malloc(index + 2);
    strncpy(substr, ch, index + 1);
    substr[index + 1] = 0;
    
    // ...
    
    free(substr);
    

    If you’re happy to mutilate the original string, just insert a null byte:

    ch[index + 1] = 0;
    

    The odd + 1 comes from the fact that your index seems to be inclusive, which is generally a bad idea.

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

Sidebar

Related Questions

If I have a character pointer that contains NULL bytes is there any built
I have a constructor, that receives a character pointer. If it is empty, I
I have a pointer to a character array: space=(char**)calloc(100000,sizeof(char*)); for(i=0;i<100000;i++){ space[i]=(char*)calloc(1,sizeof(char)); } such that
i have a character controller which jumps but while jumping i want to change
I have an html special character I want to toggle off and on like
I have a function that needs to remove leading whitespace from a string. For
so, I have a ragged array (called names) of length 200. each pointer in
I have one charater pointer array which points to the some stirngs every element
I have two questions: Q1. The character pointers are used to point to a
Hey so im struggling hard. I need to create a random string (of length

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.