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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:57:53+00:00 2026-06-16T19:57:53+00:00

I have a character buffer which will contain text in this format. somecontent…boundary=abc_is_the_boundary content-length=1234

  • 0

I have a character buffer which will contain text in this format.

somecontent...boundary="abc_is_the_boundary"
content-length=1234

--abc_is_the_boundary
somecontent
--abc_is_the_boundary

This buffer is stored in char * buf;

Now my objective is identify the boundary value which is abc_is_the_boundary in this case and pass all the contents in the buffer under that boundary to a function and get a new string which will replace it. Even --abc_is_the_boundary will be sent to the function.

So in this case the buffer passed to the function will be

--abc_is_the_boundary
somecontent
--abc_is_the_boundary

After processing, say it returns xyz.

The content-length has changed to 3 and now the resulting buffer must look like this

somecontent...boundary="abc_is_the_boundary"
    content-length=3

xyz

I can identify the boundary value using strstr. But how do I find first instance of the boundary and last instance of the boundary? the boundary can be there multiple times, but only first and last have to be found. The content-length can be modified by using strstr again, and go to the speicific location and modified. Is that the best way.

I hope you have understood

  • 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-16T19:57:55+00:00Added an answer on June 16, 2026 at 7:57 pm

    You can use simple pointer arithmetic for finding the first and the last occurrence of the pattern. Think about it this way: For the first appearance of the pattern you use the first result of strstr, since this is exactly what this function was designed for. Then you ask yourself “is there another occurrence of the pattern after the first one” and use strstr again for this. You repeat this until you find no further occurrence. The last one you found must then be the last one in the whole buffer.

    It would then look somewhat like this. The code below is neither compiled, nor tested, but the idea should be clear:

    char *buf, *pattern, *firstOcc, *lastOcc, *temp;
    
    // ... extract pattern from buffer
    
    firstOcc = strstr(buf, pattern);
    temp = firstOcc;
    
    do {
      lastOcc = temp;
      temp = strstr(lastOcc + 1, pattern);
    } while(temp != 0);
    

    By searching from the last found location + 1 you exclude the last location, whence strstr will deliver to you the location after the last one found.

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

Sidebar

Related Questions

I have two paragraphs in a buffer which has only simple text in it:
I have a input stream IPCimstream, which returns a pointer to the character buffer
i have a character controller which jumps but while jumping i want to change
Basically I have void FileReader::parseBuffer(char * buffer, int length) { //start by looking for
I have a child process which generates some output of variable length and then
The documentation says the cin.get(...) will leave the termination character(parameter t) in the buffer!
I have a encoded character buffer array of size 512 in C, and a
I have an oracle function which is given below. when I run this in
I have a character array and I'm trying to figure out if it matches
I have a character (whose (x, y) position is stored in bodyc), and a

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.