datastructures with javascript

  • Thread starter Sumaira Maqsood Ali
  • Start date
S

Sumaira Maqsood Ali

HI,
I have a C program that outputs html code and embedded javascript code.
I have a datastructure in my C file whose data values have to be
printed dyanamically by javascript when the viewer clicks on the
corresponding button in the browser. Is there a way I can make this
datastructure in C file available to Javascript when the viewer request
to see that information.
Thanks
Sumaira
 
B

Berislav Lopac

Sumaira said:
HI,
I have a C program that outputs html code and embedded javascript
code. I have a datastructure in my C file whose data values have to
be printed dyanamically by javascript when the viewer clicks on the
corresponding button in the browser. Is there a way I can make this
datastructure in C file available to Javascript when the viewer
request to see that information.

Sure there is. Just remember that C structures are just like object without
methods, and that Javascript is an object-oriented language.

So, if you have a structure going like this:

struct myStruct
{
char myVar[11];
int myVar2;
struct subStruct
{
char mySubVar1[5];
int mySubVar2;
}
} my_structure;

You can easily convert it into a JS object similar to this:

var myObject = new Object();
myObject.myVar1 = "write the value of myStruct.myVar here";
myObject.myVar2 = 100;
myObject.subObject = new Object();
myObject.subObject.mySubVar1 = "text";
myObject.subObject.mySubVar2 = 285;

Berislav
 
R

Richard Cornford

... . Just remember that C structures are just like object
without methods, and that Javascript is an object-oriented
language.
So, if you have a structure going like this:

struct myStruct
{
char myVar[11];
int myVar2;
struct subStruct
{
char mySubVar1[5];
int mySubVar2;
}
} my_structure;

You can easily convert it into a JS object similar to this:

var myObject = new Object();
myObject.myVar1 = "write the value of myStruct.myVar here";
myObject.myVar2 = 100;
myObject.subObject = new Object();
myObject.subObject.mySubVar1 = "text";
myObject.subObject.mySubVar2 = 285;

Or do the same using the slightly more compact JS Object literal
notation:-

var myObject = {
myVar1:"write the value of myStruct.myVar here",
myVar2:100,
subObject:{
mySubVar1:"text",
mySubVar2:285
}
};

Richard.
 

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
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top