Tokenizer does not like ampersand

Discussion in 'C++' started by keepyourstupidspam@yahoo.co.uk, Aug 25, 2006.

  1. 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
    , Aug 25, 2006
    #1
    1. Advertising

  2. wrote:
    > 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
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Aug 25, 2006
    #2
    1. Advertising

  3. Guest

    Victor Bazarov wrote:
    > wrote:
    > > 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
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask



    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
    , Aug 25, 2006
    #3
  4. wrote:
    > [..]
    > 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
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Aug 25, 2006
    #4
  5. Bo Persson Guest

    <> skrev i meddelandet
    news:...
    >
    > Victor Bazarov wrote:
    >>
    >> The error is in your tokenize function, on line 42. See FAQ 5.8.
    >>


    >
    > 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
    Bo Persson, Aug 25, 2006
    #5
  6. Guest

    Bo Persson wrote:
    > <> skrev i meddelandet
    > news:...
    > >
    > > Victor Bazarov wrote:
    > >>
    > >> The error is in your tokenize function, on line 42. See FAQ 5.8.
    > >>

    >
    > >
    > > 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



    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
    , Aug 25, 2006
    #6
  7. wrote:
    > Bo Persson wrote:
    >> <> skrev i meddelandet
    >> news:...
    >>> Victor Bazarov wrote:
    >>>> The error is in your tokenize function, on line 42. See FAQ 5.8.
    >>>>
    >>> 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

    >
    >
    > 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'
    =?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=, Aug 25, 2006
    #7
  8. wrote:
    > Bo Persson wrote:
    > > <> skrev i meddelandet
    > > news:...
    > > > Victor Bazarov wrote:


    > > >> The error is in your tokenize function, on line 42. See FAQ 5.8.
    > > >
    > > > 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.)

    >
    > 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

    --
    Nick Keighley
    Nick Keighley, Aug 25, 2006
    #8
  9. Guest

    Nick Keighley wrote:
    > wrote:
    > > Bo Persson wrote:
    > > > <> skrev i meddelandet
    > > > news:...
    > > > > Victor Bazarov wrote:

    >
    > > > >> The error is in your tokenize function, on line 42. See FAQ 5.8.
    > > > >
    > > > > 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.)

    > >
    > > 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
    >
    > --
    > Nick Keighley



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


    Enda
    , Aug 25, 2006
    #9
  10. Marcus Kwok Guest

    wrote:
    > 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';
    }
    }


    --
    Marcus Kwok
    Replace 'invalid' with 'net' to reply
    Marcus Kwok, Aug 25, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tfortney

    Ampersand in attribute

    tfortney, Apr 27, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,184
    tfortney
    Apr 28, 2004
  2. Prasanna Padmanabhan
    Replies:
    1
    Views:
    642
    Kevin Spencer
    Jul 8, 2004
  3. Rodusa

    Ampersand problem

    Rodusa, Feb 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,392
    Rodusa
    Feb 9, 2005
  4. Replies:
    6
    Views:
    1,362
    Andrew Lampert
    Jul 8, 2006
  5. Marek
    Replies:
    5
    Views:
    228
    Peter J. Holzer
    Aug 31, 2009
Loading...

Share This Page