![]() |
| | #1 |
| Registered User Join Date: Jan 2009
Posts: 37
| i'm very new to C Programming, but i'm learning quite well... how can i parse only a part of a string? my string is always like this: Code: GET /send.htm?Text=START HTTP/1.1 i need to retrieve that part only and save into an variable. how can i do this? i would appreciate it if some one could help me with this, an example code or something would be really nice. ![]() thanking you in advance |
| Ali.B is offline | |
| | #2 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| Use strchr() to get the location of the '='. Then use strchr() again to get the location of the space after the equals sign. Finally use strncpy() to copy out the characters between those 2 locations.
__________________ bit∙hub [bit-huhb] n. A source and destination for information. |
| bithub is offline | |
| | #3 |
| Registered User Join Date: Jan 2009
Posts: 37
| can u give an example? I've never worked with those functions.... or a link that provides some examples. ![]() thanks |
| Ali.B is offline | |
| | #4 |
| DESTINY Join Date: Jul 2008 Location: in front of my computer
Posts: 656
|
__________________ HOPE YOU UNDERSTAND....... for( ; ; ) printf("If you can't make it good, at least make it look good"); PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D. IDE- Microsoft Visual Studio 2008 Express Edition |
| BEN10 is offline | |
| | #5 | |
| Novice Join Date: Jul 2009
Posts: 32
| Quote:
| |
| msh is offline | |
| | #6 |
| Registered User Join Date: Jan 2009
Posts: 37
| I looked at those examples, but I'm still lost... can someone post a piece of code that could demonstrate the use of strchr() and strncpy()? |
| Ali.B is offline | |
| | #7 |
| Registered User Join Date: Mar 2003
Posts: 169
| Code: char Text[80] = {0};
char * line = "GET /send.htm?Text=START HTTP/1.1";
char *s,*t;
if(s = strchr(line, '='))
{
if(t = strchr(s, ' '))
strncpy(Text, s+1, t-s);
}
printf("Text = %s\n", Text);
|
| Scarlet7 is offline | |
| | #8 |
| Banned Join Date: Aug 2009
Posts: 43
| there is much easyer way if str="123456" sscanf(str,"%3d",&num); num will be 123 |
| kakaroto is offline | |
| | #9 |
| Registered User Join Date: Jan 2009
Posts: 37
| Thanks a million Scarlet7, now I understand how to use it |
| Ali.B is offline | |
![]() |
| Tags |
| parse, part, 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 |
| String editor for a sentence inputted by a user - any suggestions or ideas? | the_newbug | C Programming | 4 | 03-03-2006 02:11 AM |
| String Parse. | Coder87C | C# Programming | 3 | 08-16-2005 02:18 AM |
| Errors | Rhidian | C Programming | 10 | 04-04-2005 12:22 PM |