By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,621 Members | 1,775 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,621 IT Pros & Developers. It's quick & easy.

How to put %s within alert

P: n/a
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",Buf);

I am getting error "Unterminated string literal in the javascript
console

alert("Test

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

Thanks
Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a


Vanitha wrote:

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

unsigned char Buf="Test";
Are you sure you wouldn't need
unsigned char *Buf = "Test";
printf("alert(\"%s\");\n\n",Buf);

I am getting error "Unterminated string literal in the javascript
console

alert("Test

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


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/
Jul 23 '05 #2

P: n/a
va*****@agilis.st.com.sg (Vanitha) writes:
Is there anything wrong with this syntax..I am generating javascript
code from "C" language.
It's not a Javascript problem, but a C problem.
unsigned char Buf="Test";
Should be
char *Buf = "Test";

As it is, you are assigning a pointer to a char variable. Only fun
can come from that :)
printf("alert(\"%s\");\n\n",Buf);

I am getting error "Unterminated string literal in the javascript
console

alert("Test

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


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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3

P: n/a
In article <15**************************@posting.google.com >,
va*****@agilis.st.com.sg enlightened us with...
Hi All,
Is there anything wrong with this syntax..I am generating javascript
code from "C" language.

unsigned char Buf="Test";
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. :)


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


Are you SURE? ;)

--
--
~kaeli~
Condoms should be used on every conceivable occasion.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4

P: n/a
Lee
Vanitha said:

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",Buf);

I am getting error "Unterminated string literal in the javascript
console

alert("Test

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


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.

Jul 23 '05 #5

P: n/a
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 <ti******@NOSPAM.comcast.net> wrote in message news:<MP************************@nntp.lucent.com>. ..
In article <15**************************@posting.google.com >,
va*****@agilis.st.com.sg enlightened us with...
Hi All,
Is there anything wrong with this syntax..I am generating javascript
code from "C" language.

unsigned char Buf="Test";


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. :)


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


Are you SURE? ;)

--

Jul 23 '05 #6

P: n/a
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(au8RespBuf,"Config set successfully\n");
}else
{
//Decode the error code here....and form the correct error string
strcpy(au8RespBuf,"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.

Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.