C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-06-2009, 05:07 PM   #1
Registered User
 
Join Date: Jan 2009
Posts: 37
Post Parse A Part of String

Hello Guys...
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
only the "START" part can change according to user input, but that part is always after the "=" sign and before " " (the space) before HTTP.
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   Reply With Quote
Old 08-06-2009, 05:21 PM   #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   Reply With Quote
Old 08-07-2009, 06:12 AM   #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   Reply With Quote
Old 08-07-2009, 06:28 AM   #4
DESTINY
 
BEN10's Avatar
 
Join Date: Jul 2008
Location: in front of my computer
Posts: 656
Here
__________________
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   Reply With Quote
Old 08-07-2009, 06:28 AM   #5
msh
Novice
 
Join Date: Jul 2009
Posts: 32
Quote:
Originally Posted by Ali.B View Post
can u give an example? I've never worked with those functions.... or a link that provides some examples.
thanks
cstring (string.h) - C++ Reference
msh is offline   Reply With Quote
Old 08-07-2009, 01:42 PM   #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   Reply With Quote
Old 08-07-2009, 02:17 PM   #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   Reply With Quote
Old 08-07-2009, 02:41 PM   #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   Reply With Quote
Old 08-07-2009, 03:07 PM   #9
Registered User
 
Join Date: Jan 2009
Posts: 37
Thanks a million Scarlet7, now I understand how to use it
Ali.B is offline   Reply With Quote
Reply

Tags
parse, part, string

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 09:26 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22