![]() |
| | #1 |
| Registered User Join Date: Jan 2009
Posts: 37
| i managed to parse the parts that i need from this string: Code: "GET /send.htm?Text=START+00500+11611 HTTP/1.1" ):Code: char Text[80] = {0};
char * line = "GET /send.htm?Text=START+00500+11611 HTTP/1.1";
char *s,*t;
char bt_msg[20] = {0};
if(s = strchr(line, '+'))
{
if(t = strchr(s, ' '))
strncpy(Text, s+1, t-s);
}
char *xcoord=strtok(Text,"+"), *ycoord=strtok(NULL,"+");
printf("x-coord:%s\n", xcoord);
printf("y-coord:%s\n", ycoord);
}
the output will be: Code: x-coord: 00500 y-coord: 11611 Code: "X=00500Y=11611" i need to save assemble this payload from those coordinates and put in a variable so i can use it later on.may be save it as bt_msg. how could i do it? thanks Last edited by Ali.B; 08-12-2009 at 04:30 AM. |
| Ali.B is offline | |
| | #2 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 1,929
| sprintf() is probably what you want to use, or, you can use a series of strcat() functions.
__________________ Mac and Windows cross platform programmer. Ruby lover. Memorable Quotes From Recent Posts: I can't remember. |
| Dino is offline | |
| | #3 |
| Registered User Join Date: Jan 2009
Posts: 37
| could u show me how with a piece of code? with both functions; sprintf() and strcat(); |
| Ali.B is offline | |
| | #4 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 1,929
| Code: char a[] = "A" ;
char b[] = "B" ;
char c[] = "C" ;
char abc[10] = {0} ;
strcat(abc, a) ;
strcat(abc, b) ;
strcat(abc, c) ;
printf("variable abc = %s\n", abc) ;
__________________ Mac and Windows cross platform programmer. Ruby lover. Memorable Quotes From Recent Posts: I can't remember. |
| Dino is offline | |
| | #5 |
| Registered User Join Date: Jan 2009
Posts: 37
| yes i understood this part... and I can use it now... thanks for the sample code ![]() the output will be this; since my variables are xcoord and ycoord; 0050011611 now how can i add other characters to this string? and make it look like this: X=00500Y=11611 X,= and Y should be added to the string.. how can i handle this? |
| Ali.B is offline | |
| | #6 | |
| Registered User Join Date: Jan 2009
Posts: 37
| Quote:
![]() i did like this: Code: int main()
{
char Text[80] = {0};
char * line = "GET /send.htm?Text=START+00500+11611 HTTP/1.1";
char *s,*t;
char bt_msg[20] = {0};
if(s = strchr(line, '+'))
{
if(t = strchr(s, ' '))
strncpy(Text, s+1, t-s);
}
char *xcoord=strtok(Text,"+"), *ycoord=strtok(NULL,"+");
printf("x-coord:%s\n", xcoord);
printf("y-coord:%s\n", ycoord);
strcat(bt_msg, "X=");
strcat(bt_msg, xcoord);
strcat(bt_msg, "Y=");
strcat(bt_msg, ycoord);
printf("bt_msg= %s\n", bt_msg) ;
}
Code: bt_msg= X=00500Y=11611 | |
| Ali.B is offline | |
| | #7 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 1,929
| Glad you figured it out. That's what it's all about - you learning through experimentation and trial and error.
__________________ Mac and Windows cross platform programmer. Ruby lover. Memorable Quotes From Recent Posts: I can't remember. |
| Dino is offline | |
| | #8 |
| Registered User Join Date: Jan 2009
Posts: 37
| Exactly.... |
| Ali.B is offline | |
![]() |
| Tags |
| string |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Inheritance Hierarchy] User Input on program with constructors. How ? | chandreu | C++ Programming | 8 | 04-25-2008 02:45 PM |
| Help! Homework using Strings | wco5002 | C++ Programming | 16 | 09-27-2007 03:53 AM |
| Calculator + LinkedList | maro009 | C++ Programming | 20 | 05-17-2005 12:56 PM |
| Classes inheretance problem... | NANO | C++ Programming | 12 | 12-09-2002 03:23 PM |
| "Operator must be a member function..." (Error) | Magos | C++ Programming | 16 | 10-28-2002 02:54 PM |