Newbie question on string/pchar parsing.

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Newbie question on string/pchar parsing.

Postby aappleton » Fri Oct 10, 2003 5:13 am

Hello, I am a Java/VB developer that has suddenly been plunged into the C/C++ world, so I hope somebody can answer a question for me.
I have written some code that takes as a parameter an array of pchar:

char *arg_v[]

A typical parameter would be:

Param1='Value1'
in that format. What I would like to do is take the text between the single quotes, and assign that either to a string, or another pchar.

I have made some code, and it works - to a point, but it is very long and looks complicated, so is bad for maintenance. Also, it is probably error-prone.

Is there any string/pchar handling function in C/C++ that can perform this in a single operation?

Thanks,
AA.
aappleton
 

Postby devil_slayer » Fri Oct 10, 2003 6:18 am

In C I'd look at a function called "sscanf()" and its friends...
User avatar
devil_slayer
 
Posts: 489
Joined: Wed Oct 01, 2003 3:44 am
Location: Warsaw, POLAND

Postby twm » Fri Oct 10, 2003 7:52 am

Code: Select all
char buff[1001];
...
sscanf(pair, "%*[^']'%1000[^']'", buff);
The information given in this message is known to work on FreeBSD 4.8 STABLE.
*The above statement is false if I was too lazy to test it.*
If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
twm
 
Posts: 22
Joined: Mon Sep 29, 2003 2:38 pm

Postby Raindog » Sat Oct 11, 2003 4:06 pm

twm wrote:
Code: Select all
char buff[1001];
...
sscanf(pair, "%*[^']'%1000[^']'", buff);


Thanks, that was helpful.
Raindog
 


Return to For Beginners

Who is online

Users browsing this forum: Google Adsense [Bot] and 2 guests

cron