473,513 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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",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
6 1703


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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
11164
by: relaxedrob | last post by:
Howdy All! I am really stuck with this one - I want to completely create a table within JavaScript and insert it into the document, with onMouseOut and onMouseOver handlers in the table rows. Below is a sample of the code I have created. It all works in Netscape 7.1, but in IE 6 it shows the table but the handlers do not run. I can prove...
3
2768
by: Tommo | last post by:
Hello All, I am a still learning so be easy on me. I am trying to get some code to work that is using JS and Perl/CGI, I am using AS Perl and an Apache Server on XP as the webserver. Can anyone take a look at the code and tell me why I am getting Apache Server errors in the code below (Part A), when I modify the code as shown in part B the...
26
8028
by: johkar | last post by:
I need to cancel the link and execute a function onclick of all the links within the span tag which has a class of "container" assigned. There will be only one span tag with this class applied. I know you can get a specific tag using document.getElementsByTagName('span'), but I am unsure how to get the one with the class="container". I...
1
2312
by: 4Ankit | last post by:
Hey guys i am having some trouble with nesting one selection structure within another selection structure. At the moment i am unclear what selection structures are and just need a simple example of a selection structure within another selection structure. I am supposed to use function definitions with parameters to validate a form. my code...
6
5043
by: Dan | last post by:
Excuse me if i'm being a bit thick here, but is it possible to reference a server side variable within an embedded js source file. For example, my test.js file contains alert('<%=tmpVar%>'); and my aspx page contains:- <script type="text/javascript" src="test.js">
1
2107
by: webgour | last post by:
Hello, I would like to create an onload event within my object. The following works fine : function TEST() { this.image= new Image(); } TEST.prototype.Initialize = function()
7
6236
by: -Lost | last post by:
I am calling setTimeout within the context of an object, and whilst this exists, it refuses to be passed along to the function I call. For example: $elemById('id').change = function() { // the function returns the object itself, 'this' exists alert(this); // setTimeout('alert(this);',1000); // }
9
1127
by: Morlaath | last post by:
Is there a way to embed php within javascript code? I know that php is server side and js is client side. For instance when working with jsp, you can imbed jsp scriptlets within the js code. e.g <script language="javascript"> function foo() { var bar = <%=(java variable)%>
22
1667
by: DL | last post by:
Hi, What I wanted to do is to call a function from a newly created element. But it stumbled me. Here's the line that references the newly created element and I used the alert function for debugging for now. Did I mess up all these quotes? // once again this is the key line of code, problem area, disregard
7
2370
by: vunet | last post by:
I am still not clear about how to reference an object within another object to pass first object to a function: var Parent = { myFunc : function(){ alert("Parent = "+this) }, Child : { //how to get reference to Parent? myChildFunc : function(){
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.