I have a structure, say
typedef struct
{
char a[10];
char b[10];
int i;
} test;
Based on the user input of how many instances to create , i should create instances prefixed with runtime data.
For ex., if user says 3 which has to be prefixed with "US", i need to create
test *UStesting1;
test *UStesting2;
test *UStesting3;
and i need to load various file into each instance.
For e.g, USTesting1 will contain data from File US1.in;
USTesting2 will contain data from File US2.in;
& USTesting2 will contain data from File US3.in;
Again, i'm using malloc and free to decide the size of the array structure based on the number of entries in input file.
How can i do this?
Can anyone help me on this, since this is a bit urgent!!
Thanks in advance,
Priya
4 2080 Savage 1,764
Recognized Expert Top Contributor
I have a structure, say
typedef struct
{
char a[10];
char b[10];
int i;
} test;
Based on the user input of how many instances to create , i should create instances prefixed with runtime data.
For ex., if user says 3 which has to be prefixed with "US", i need to create
test *UStesting1;
test *UStesting2;
test *UStesting3;
and i need to load various file into each instance.
For e.g, USTesting1 will contain data from File US1.in;
USTesting2 will contain data from File US2.in;
& USTesting2 will contain data from File US3.in;
Again, i'm using malloc and free to decide the size of the array structure based on the number of entries in input file.
How can i do this?
Can anyone help me on this, since this is a bit urgent!!
Thanks in advance,
Priya
U will need to run a programm that will edit code of programm which have class instances then compile it in command line and run it.
Now,which compiler do u use?
Savage
You can't dynamically create variable names. I believe you have mis-interpreted your assignment.
Banfa 9,065
Recognized Expert Moderator Expert
I have a structure, say
typedef struct
{
char a[10];
char b[10];
int i;
} test;
Based on the user input of how many instances to create , i should create instances prefixed with runtime data.
For ex., if user says 3 which has to be prefixed with "US", i need to create
test *UStesting1;
test *UStesting2;
test *UStesting3;
and i need to load various file into each instance.
For e.g, USTesting1 will contain data from File US1.in;
USTesting2 will contain data from File US2.in;
& USTesting2 will contain data from File US3.in;
Again, i'm using malloc and free to decide the size of the array structure based on the number of entries in input file.
How can i do this?
I would create a containing structure -
typedef struct
-
{
-
char prefix[10];
-
int count;
-
test *array;
-
} test_container;
-
Then you can fill in prefix and count with input from the user. Use count to malloc an array of test structures and store in the array member. Then you can iterate through each of these structures open the file and fill in the structure.
Pseudo coded as -
test_container container;
-
-
container.prefix = GetPrefixFromUser();
-
-
container.count = GetCoutFromUser();
-
-
container.array = (test *)malloc(sizeof *container.array * continer.count);
-
-
for ix = 0 to count -1
-
{
-
filename = continer.prefix + (ix+1) + ".in"
-
-
Load continer.array[ix] from filename
-
}
-
Going back to the original problem, if the user says 3 you need to have: -
test *UStesting1;
-
test *UStesting2;
-
test *UStesting3;
-
So, you malloc() and array of 3 test: -
test* arr = (test*)malloc(3 * sizeof(test));
-
Yes?
So you use arr[0] instead of UStesting1, arr[1] instead of UStesting2 and arr[2 ] instead of UStesting3.
You cannot create variable names at run time but you can allocate an array whose size won't be known until run time and if you do that, the array elements can be used as variable names.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: grondaia |
last post by:
Here's my situation:
I have an ODBC DSN setup for Timberline Data (An accounting package
that uses pervasive.sql) on my sql box. I set up a linked server using
the supplied timberline odbc...
|
by: Kevin Little |
last post by:
#!/usr/bin/env python
'''
I want to dynamically add or replace bound methods in a class. I want
the modifications to be immediately effective across all instances,
whether created before or...
|
by: Kiyomi |
last post by:
Hello,
I create a Table1 dynamically at run time, and at the same time, I would
like to create LinkButton controls, also dynamically, and insert them into
each line in my Table1. I would...
|
by: Michael C |
last post by:
Hi all,
I am currently using a Win32 API call to NetServerEnum to enumerate all SQL
Servers on an NT Domain. The function returns the names of all servers
running SQL Server on the network, but...
|
by: Michael C |
last post by:
Hi all,
After a lot of research, I've come to some realizations about enumerating
Named Instances of MSDE. NetServerEnum() Win32 API function doesn't work,
SQL-DMO doesn't work, no standard...
| |
by: Thomas W. Brown |
last post by:
If I am using the CSharpCodeProvider to dynamically compile an in-memory
assembly from some C# source, do I need to worry about signing this assembly
if I'm doing the compilation, instantiation,...
|
by: David Fort |
last post by:
Hi,
I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a
function provided in a DLL.
The function takes the address of a structure which it will fill in with
values.
I...
|
by: Pacific Fox |
last post by:
Hi all,
haven't posted to this group before, but got an issue I can't work
out... and hoping to get some help here ;-)
I've got a base object that works fine with named arguments when called...
|
by: |
last post by:
I have made some user controls with custom properties. I can set those
properties on instances of my user controls, and I have programmed my user
control to do useful visual things in response to...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
| |