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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:20:50+00:00 2026-05-23T02:20:50+00:00

I have a C++ function that splits LPSTR type variable an attact it into

  • 0

I have a C++ function that splits LPSTR type variable an attact it into an char array (char*)
Example:

this->XMeshTexturePath = FindTexturePath(XMeshTexturePath,d3dxMaterials[i].pTextureFilename);
   //the value of XMeshTexturePath is: Models\\Textures\\
   //the value of d3dxMaterials[i].pTextureFilename is: BlaBlaBla\\BlaBla\\Cyrex.x
   //The Result(XMeshTexturePath) should be like this:"Models\\Textures\\Cyrex.x"

This is the funcion I’m trying to write:

int FindTextLength(char* Text){
    int length

h=0;
for(int i=0;i

char* FindTexturePath( char* TexturePath ,LPSTR FileNameToCombine){
    int FileLength=0;
    int PathAndFileLength=0;
    char *FileName = new char;
    char *TexPathAndName = new char;

    strcpy(TexPathAndName, FileNameToCombine);
    PathAndFileLength = FindTextLength(TexPathAndName);

    for(int i=0; i<PathAndFileLength; i++){
        if( TexPathAndName[i] != NULL){
            if(TexPathAndName[i] != '\\'){
                FileName[FileLength] = TexPathAndName[i];
                FileLength++;
            }
            else 
                FileLength = 0 ;
        }else break;
    }

    int PathLength = FindTextLength(TexturePath);
    char *Result = new char;
//==============>> // I also tryed this:char *Result = new char[PathLength+FileLength];
//==============>> //                   char *Result = new char();

    for(int i=0; i<PathLength; i++){
        if( TexturePath[0] != NULL){
            Result[i] = TexturePath[i];
        }
        else break;
    }

    for(int i=0; i<FileLength; i++){
        if( FileName[0] != NULL){
            Result[PathLength + i] = FileName[i];
        }
        else break;
    }

    return **Result**; // The Problem is here It should be like this:
                       // "Models\\Textures\\Cyrex.x"
                       // But I'm taking one of these as result:
                       //    "Models\\Textures\\Cyrex.x{"
                       //    "Models\\Textures\\Cyrex.xu"
                       //    "Models\\Textures\\Cyrex.xY"
                       //    The last character is random... 8O(
}

Actualy it’s not wokring so bad. The problem is when I declare an char array(char *Result = new char;) it does’not metter how much is length I’m takin an extra character at the end of final result(Result)
I’m realy stucked in here if you have any idea or suggestion plase let me know.
Thanks for any advice and respons.

The Solusion is adding this at the end
of function:

            Result[i] = TexturePath[i];
        }
        else break;
    }

    for(int i=0; i<FileLength; i++){
        if( FileName[0] != NULL){
            Result[PathLength + i] = FileName[i];
        }
        else break;
    }
    Result[PathLength+FileLength] = '\0' ;  // This part is resloving the problem.
                                            // **Thanks for helps**.
    return Result;
}
  • 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-23T02:20:51+00:00Added an answer on May 23, 2026 at 2:20 am
    char *Result = new char[PathLength+FileLength];
    

    Result pointed data should end with the termination character \0. Or you will run into problems when returned such a string pointed by Result. So,

    Result[PathLength+FileLength-1] = '\0' ;
    

    Make sure you never overrun the buffer or even a better option is to use std::string.

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

Sidebar

Related Questions

I have this code, that takes a string and splits it into an array:
I have a function that is supposed to split my array into smaller, evenly
I have a function that splits a multipage tiff into single pages and it
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
I have a function that automatically exports a table into a CSV file, then
I have written this piece of code that splits a string and stores it
Ok so I have this function that when a contact is clicked it adds
I have a function that whenever it is called it splits the window and
I need to write a function that splits records into separate files based on
So I have function that formats a date to coerce to given enum DateType{CURRENT,

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.