Learn how to a build a cloud-first strategyRegister Now


Extracting a particular part from a message

Posted on 2005-04-28
Medium Priority
Last Modified: 2013-11-13
I just want to extract a particular part of message using start and end boundaries.
For example
<start Boundary value > [filename="admissionnotices.html"]
<some text to be extracted>
<end Boundary value> [------=_Part_376_20547182.1114753430061]

Content-Type: audio/mpeg; name="SuttumVizhi.mp3"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
<start Boundary value > [filename="SuttumVizhi.mp3"]
<some text to be extracted>
<end Boundary value> [------=_Part_376_20547182.1114753430061]

in the above example  the start boundary will be "filename" and the end boundary will be "[------=_Part_376_20547182.1114753430061]"
now by giving these value as input i have to extract the content between these boundaries in C.

How to do this

Reply me

With Regards,

Question by:priyashree

Accepted Solution

lubovec earned 100 total points
ID: 13892441

I think this is job for sscanf function. see http://www.cplusplus.com/ref/cstdio/sscanf.html for description and example

hope this helps


Assisted Solution

TheC2 earned 100 total points
ID: 13892622
Assuming the filename and the part number changes, you can search for "[filename=", then search for the following "]", add 1 and you've got your start index.
Search for "[------=_Part" and substract 1 and you got your end index.
Then extract the string in between them.
You can use the strstr function to serach for those substrings, and then the strncpy to get the substring.
The code should look something like this:

char* s = <your string>;
char* substring;
int start_index, end_index;

// Get the start index.
start_index = strstr(s, "[filename=");
start_index = strstr(s + start_index, "]");

// Get the end index.
end_index = strstr(s, "[------=_Part");

substring = calloc(end_index - start_index + 1, sizeof(char));
strncpy(substring, start_index, end_index - start_index);

Good luck!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Simple Linear Regression

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question