How to put %s within alert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vanitha

    #1

    How to put %s within alert

    Hi All,
    Is there anything wrong with this syntax..I am generating javascript
    code from "C" language.

    unsigned char Buf="Test";
    printf("alert(\ "%s\");\n\n",Bu f);

    I am getting error "Unterminat ed string literal in the javascript
    console

    alert("Test

    but i have terminated this string in my "c" code..?

    Thanks
  • Martin Honnen

    #2
    Re: How to put %s within alert



    Vanitha wrote:

    [color=blue]
    > Is there anything wrong with this syntax..I am generating javascript
    > code from "C" language.
    >
    > unsigned char Buf="Test";[/color]

    Are you sure you wouldn't need
    unsigned char *Buf = "Test";
    [color=blue]
    > printf("alert(\ "%s\");\n\n",Bu f);
    >
    > I am getting error "Unterminat ed string literal in the javascript
    > console
    >
    > alert("Test
    >
    > but i have terminated this string in my "c" code..?[/color]

    Hard to tell, if there really is
    alert("Test
    send to the browser then the script engine is right to flag the syntax
    error.
    You might want to ask in a C group perhaps as it is more a problem using
    C to generate some string in a certain output format than being a
    JavaScript problem.
    If you have a public URL where the problem occurs then you could post it
    here so that we can at least check whether other browsers have the same
    problem. Which browser did you test with?


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: How to put %s within alert

      vanitha@agilis. st.com.sg (Vanitha) writes:
      [color=blue]
      > Is there anything wrong with this syntax..I am generating javascript
      > code from "C" language.[/color]

      It's not a Javascript problem, but a C problem.
      [color=blue]
      > unsigned char Buf="Test";[/color]

      Should be
      char *Buf = "Test";

      As it is, you are assigning a pointer to a char variable. Only fun
      can come from that :)
      [color=blue]
      > printf("alert(\ "%s\");\n\n",Bu f);
      >
      > I am getting error "Unterminat ed string literal in the javascript
      > console
      >
      > alert("Test
      >
      > but i have terminated this string in my "c" code..?[/color]

      Yes, otherwise the C compiler would have complained.
      My guess is that the pointer is converted to the char value zero.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • kaeli

        #4
        Re: How to put %s within alert

        In article <15faa2ac.05032 80100.23c0a07a@ posting.google. com>,
        vanitha@agilis. st.com.sg enlightened us with...[color=blue]
        > Hi All,
        > Is there anything wrong with this syntax..I am generating javascript
        > code from "C" language.
        >
        > unsigned char Buf="Test";[/color]

        Um...
        This isn't ANSI C.
        An unsigned char is ONE character. Not a string.
        Are you missing a pointer (*) or some brackets([]), or is this not ANSI C? If
        this is C# or C++, mention that. :)

        [color=blue]
        >
        > but i have terminated this string in my "c" code..?[/color]

        Are you SURE? ;)

        --
        --
        ~kaeli~
        Condoms should be used on every conceivable occasion.



        Comment

        • Lee

          #5
          Re: How to put %s within alert

          Vanitha said:[color=blue]
          >
          >Hi All,
          >Is there anything wrong with this syntax..I am generating javascript
          >code from "C" language.
          >
          >unsigned char Buf="Test";
          >printf("alert( \"%s\");\n\n",B uf);
          >
          >I am getting error "Unterminat ed string literal in the javascript
          >console
          >
          >alert("Test
          >
          >but i have terminated this string in my "c" code..?[/color]

          The alert results look like you've got a newline character in Buf.
          You don't show one in your example, but since your example is bad C syntax, I'm
          guessing that you've wasted people's time by posting code that's "sorta like"
          what you really have.

          Comment

          • Vanitha

            #6
            Re: How to put %s within alert

            Sorry that was a typo error. I am assigning the string to a character
            array only..I am using Mozilla browser. I am getting the error message
            alert("Test Unterminated string literal in the Javascript console...
            But actually i am terminating the string properly in my printf
            statement for the alert message


            kaeli <tiny_one@NOSPA M.comcast.net> wrote in message news:<MPG.1cb1d 0f8fbb1ffda98a3 dc@nntp.lucent. com>...[color=blue]
            > In article <15faa2ac.05032 80100.23c0a07a@ posting.google. com>,
            > vanitha@agilis. st.com.sg enlightened us with...[color=green]
            > > Hi All,
            > > Is there anything wrong with this syntax..I am generating javascript
            > > code from "C" language.
            > >
            > > unsigned char Buf="Test";[/color]
            >
            > Um...
            > This isn't ANSI C.
            > An unsigned char is ONE character. Not a string.
            > Are you missing a pointer (*) or some brackets([]), or is this not ANSI C? If
            > this is C# or C++, mention that. :)
            >
            >[color=green]
            > >
            > > but i have terminated this string in my "c" code..?[/color]
            >
            > Are you SURE? ;)
            >
            > --[/color]

            Comment

            • vanitha@agilis.st.com.sg

              #7
              Re: How to put %s within alert

              Thanks for your replies. That solved the problem. It was the newline
              char causing the problem.

              I was actually copying some string to my buffer based on some
              condition...

              unsigned char au8RespBuf[40];

              if(i32RetCode == SUCCESS)
              {
              strcpy(au8RespB uf,"Config set successfully\n" );
              }else
              {
              //Decode the error code here....and form the correct error string
              strcpy(au8RespB uf,"Config Failed\n");
              }
              Now when i remove the Newline char its working fine.sorry for the
              confusion. next time onwards i will post the original code.

              Thanks.

              Comment

              Working...