Tokenizer does not like ampersand

G

Guest

Hi,

I am passing a string to my tokenize function, if the string contains
an ampersand character only the string as far as the & character gets
inputted to the function.

these parameters work fine

name;address1;address2;addres3

these break it

name;address1;add & rest;addres3

the semi colon is the delimiter used in the tokenize function.

the string parameter to the tokenize function in the good instance is
this

inString="name;address1;address2;addres3";

in the instance containing the & it is:

inString="name;address1;add ";


Anyone know why the & character terminates the string? This results in
the tokenize function not receiving the full string.

Thanks and appreciate your help.
Enda
 
V

Victor Bazarov

I am passing a string to my tokenize function, if the string contains
an ampersand character only the string as far as the & character gets
inputted to the function.

these parameters work fine

name;address1;address2;addres3

these break it

name;address1;add & rest;addres3

the semi colon is the delimiter used in the tokenize function.

the string parameter to the tokenize function in the good instance is
this

inString="name;address1;address2;addres3";

in the instance containing the & it is:

inString="name;address1;add ";


Anyone know why the & character terminates the string? This results in
the tokenize function not receiving the full string.

The error is in your tokenize function, on line 42. See FAQ 5.8.

There is one other thing I thought I'd mention: your strings also differ
in the presence of *spaces*.

V
 
G

Guest

Victor said:
The error is in your tokenize function, on line 42. See FAQ 5.8.

There is one other thing I thought I'd mention: your strings also differ
in the presence of *spaces*.

V


Hi,


How could the problem be in the tokenize function as the string
paramerer to this function is already broken by the & character


name;address1;address2;addres3
results in
inString="name;address1;address2;addres3";

name;address1;add & rest;addres3
results in
inString="name;address1;add ";


How do you know what line is giving a problem in my tokenize function?

Can anyone help me here.

Thanks.
Enda
 
V

Victor Bazarov

[..]
How could the problem be in the tokenize function as the string
paramerer to this function is already broken by the & character

It's not broken by the & character. It's most likely broken by the
space.
name;address1;address2;addres3
results in
inString="name;address1;address2;addres3";

name;address1;add & rest;addres3
results in
inString="name;address1;add ";


How do you know what line is giving a problem in my tokenize function?

I have a crystal ball.

V
 
B

Bo Persson

How could the problem be in the tokenize function as the string
paramerer to this function is already broken by the & character

It is a joke, sort of.

You asked what is wrong with the tokenize function, but you don't show
us any of the code. So Victor guessed that it might be on line 42. (Or
it might be somewhere else. We don't know.)


Bo Persson
 
G

Guest

Bo said:
It is a joke, sort of.

You asked what is wrong with the tokenize function, but you don't show
us any of the code. So Victor guessed that it might be on line 42. (Or
it might be somewhere else. We don't know.)


Bo Persson


Dudes.

Still broken even when no spaces in the input string.

name;address1;address2;addres3
results in
inString="name;address1;address2;addres3";


name;address1;add&rest;addres3 <<--- look no spaces
results in
inString="name;address1;add ";


I didn't think the tokenize code was necessary as the problem arrises
before the call to the tokenize function. The problem is the string
escapes at the & character. Why?


A little more background: the string is a parameter to an exe.

configman.exe -list name;address1;add&rest;addres3

But when I want to pass the string to the tokenize function it looks
like this:

inString="name;address1;add ";


?????

Do you still want to see the tokenize function?

Can you help me now? Go on..


Enda
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Dudes.

Still broken even when no spaces in the input string.

name;address1;address2;addres3
results in
inString="name;address1;address2;addres3";


name;address1;add&rest;addres3 <<--- look no spaces
results in
inString="name;address1;add ";


I didn't think the tokenize code was necessary as the problem arrises
before the call to the tokenize function. The problem is the string
escapes at the & character. Why?


A little more background: the string is a parameter to an exe.

configman.exe -list name;address1;add&rest;addres3

But when I want to pass the string to the tokenize function it looks
like this:

inString="name;address1;add ";
The above info would have been nice it the first place. Provide
relevant info.

Anyway. On some systems you might need to quote command
line arguments or escape certain characters as it might treat certain
characters as special.
Read the docs for your command line interpreteter, or take a quess
and try to invoke it as
configman.exe -list "name;address1;add&rest;addres3"
or
configman.exe -list 'name;address1;add&rest;addres3'
 
N

Nick Keighley

Still broken even when no spaces in the input string.

name;address1;address2;addres3
results in
inString="name;address1;address2;addres3";


name;address1;add&rest;addres3 <<--- look no spaces
results in
inString="name;address1;add ";


I didn't think the tokenize code was necessary as the problem arrises
before the call to the tokenize function. The problem is the string
escapes at the & character. Why?


A little more background: the string is a parameter to an exe.

configman.exe -list name;address1;add&rest;addres3

But when I want to pass the string to the tokenize function it looks
like this:

inString="name;address1;add ";


?????

Do you still want to see the tokenize function?


POST THE CODE

post a complete compilable program. State what the program does
and what you expect it to do
 
G

Guest

Nick said:
POST THE CODE

post a complete compilable program. State what the program does
and what you expect it to do


Thanks guys the quotes worked, you are all really really clever people.


Enda
 
M

Marcus Kwok

A little more background: the string is a parameter to an exe.

configman.exe -list name;address1;add&rest;addres3

But when I want to pass the string to the tokenize function it looks
like this:

inString="name;address1;add ";


?????

Do you still want to see the tokenize function?

Can you help me now? Go on..

<OT>
If the string is being passed in on the command line, then it is your
command interpreter that is doing the conversion. On Windows Command
Prompt, the ampersand is used to chain together commands, like
"dir&echo hi" will execute the "dir" command, then execute the "echo hi"
command.

If you want to pass the ampersand into your program, put it in double
quotes.
</OT>

Try passing your command line arguments to this program to see exactly
what is happening:


#include <iostream>

int main(int argc, char* argv[])
{
for (int i = 0; i < argc; ++i) {
std::cout << "argv[" << i << "] = " << argv << '\n';
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top