473,466 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

generating variable

5 New Member
this may sound like a stupid question though, but i am having some problem in designing the code for it.

Let us assume that we are calling a function with an arguement which is an integer corresponding to number of variables we need to generate, ie, we have to generate any number of variables dynamically. is there any method of doing this?

Thanx in advance
Mar 11 '08 #1
4 1359
sicarie
4,677 Recognized Expert Moderator Specialist
Put it in a loop where it creates an array of size (whatever you passed) and it loops that many times, each time calling your variable generator (or rand, or however you are doing it), then return the array.
Mar 11 '08 #2
ashitpro
542 Recognized Expert Contributor
this may sound like a stupid question though, but i am having some problem in designing the code for it.

Let us assume that we are calling a function with an arguement which is an integer corresponding to number of variables we need to generate, ie, we have to generate any number of variables dynamically. is there any method of doing this?

Thanx in advance
"Generating Variable" this term does not sounds good.
You can define the array dynamically
Expand|Select|Wrap|Line Numbers
  1. void allocate(int num)
  2. {
  3.    //suppose you are GENERATING(in your language) integer variables.
  4.    int * iArray;
  5.    iArray = (int *)malloc(sizeof(int)*num);
  6.    //here you can use iArray as a vector of variables; 
  7.  
  8. }
  9.  
Mar 11 '08 #3
sicarie
4,677 Recognized Expert Moderator Specialist
"Generating Variable" this term does not sounds good.
You can define the array dynamically
Expand|Select|Wrap|Line Numbers
  1. void allocate(int num)
  2. {
  3.    //suppose you are GENERATING(in your language) integer variables.
  4.    int * iArray;
  5.    iArray = (int *)malloc(sizeof(int)*num);
  6.    //here you can use iArray as a vector of variables; 
  7.  
  8. }
  9.  
And your approach will differ depending what language you are using - C or C++.
Mar 11 '08 #4
sagnik`
5 New Member
Thank you very much. But actually i was already thinking on that array implementation, i mean, dynamically allocation array with the help of malloc. But is there any way to do the "variable generation" without using the array concept?

I hope malloc can be used in this case also. But i am stuck at the point where i have to declare the same number of int pointer corresponding to the value of the argument passed.

Nevertheless, the discussion helped me. Thanks again.
Mar 16 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Eddie | last post by:
I searched with my problem but with no results :( My question is: how can I generate string, having only simple pattern, like, midend For example tyis pattern should reproduce strings like: ...
10
by: Glenn Wilson | last post by:
I have a quick Question and I Hope some one can help or at least explain. What is happening is that I am trying to use random numbers in an application, as per the sample test code below. When I...
10
by: Simon Brooke | last post by:
Here's my problem: <xsl:template match="/category"> .... <script type="text/javascript"> &lt;!]&gt; </script> .... </xsl:template>
3
by: crc128 | last post by:
Hi, I'm looking at using XML and XSLT with apache cocoon to automatically generate html files for a site. the problem I'm having is that I want one of the pages to display a google map, but the...
3
by: Patrick.O.Ige | last post by:
Hi guys, Is there any free stuff to generate DAL code out there? Thanks in advance
3
by: Sandman | last post by:
Hello, I'm building a website in PHP and Javascript. The registration portion is divided into 2 sections: 1. In one, I get info about the visitor. This is sent via POST to a php script which is...
7
by: Dag Sunde | last post by:
I want to use the format-number function to output a number with a specific number of decimals, based on the content of a node... Is there any smart way to generate differnet strings based on a...
3
by: dawnerd | last post by:
I am having troubles with my script. It is supposed to generate a "map" from a serialized array stored in a database. However, it is not generating any html. I know the data is being retrieved from...
4
by: reshmaah | last post by:
hi iam interested in generating a variable value by autoincrementing, in CGI using c as user enters some data, i want to generate an index for it, and store in a binary file with data, as...
5
by: paragpdoke | last post by:
Hello Everyone. I'm new to XSL and couldn't get something to work. Sample XML excerpt: <root> <ObjectTemplate> <NodeType1></NodeType1> <NodeType2></NodeType2> </ObjectTemplate> <Object>
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.