Dear all, I wish to copy the aray aRSG from the first function to the next. Please help, Urgent. I have attached my code - #include <stdio.h>
-
#include <string.h>
-
#include <math.h>
-
#include <stdlib.h>
-
-
// RANDON SEQUENCE GENERATOR FUNCTION
-
char RSG(int x)
-
{
-
char RandomRSG[5] = {'a','b','c','d'}; //array for sequence to be generated
-
int iRSG; // variable for counting for loop
-
char vRSG; // character variable
-
char aRSG[50]; //array to store random sequence
-
int countRSG = 0;// counter
-
int i;
-
srand(1);
-
printf("RANDOM SEQUENCE GENERATOR WILL NOW GENERATE A,B,C OR D RANDOMLY\n\n");
-
-
for (iRSG=0; iRSG<20; iRSG++)
-
{
-
if((rand()%7) == 0){
-
vRSG = RandomRSG[3];
-
}
-
else if((rand()%9) == 0){
-
vRSG = RandomRSG[2];
-
}
-
else if((rand()%3) == 0){
-
vRSG = RandomRSG[1];
-
}
-
else if(rand()%rand()!=0){
-
vRSG = RandomRSG[0];
-
}
-
aRSG[countRSG] = vRSG;
-
countRSG++;
-
-
-
-
-
}
-
for (i=0; i < 20; i++)
-
printf("%c\n", aRSG[i]);
-
return aRSG[x];
-
}
-
-
InputSelector() {
-
int y =0;
-
RSG(y);
-
int i=0, z=0, a=0, b=0, c=0, d=0, x=0;
-
char Mac1Array [20], Mac2Array [20], Mac3Array [20], Mac4Array [20];
-
char j,q=0;
-
char Selector[50] = aRSG[50];
-
-
-
for(i = 0; i<20; i= i+1) {
-
q = Selector[z];
-
-
-
-
switch(q) {
-
case 'A' :
-
-
Mac1Array [a] = Selector[z];
-
a++;
-
break;
-
case 'B' :
-
Mac2Array [b] = Selector[z];
-
b++;
-
break;
-
case 'C' :
-
Mac3Array [c] = Selector[z];
-
c++;
-
break;
-
case 'D' :
-
d++;
-
Mac4Array [d] = Selector[z];
-
-
break;
-
default:
-
break;
-
-
}
-
z++;
-
}
-
printf("THE VALUES IN MACHING ONE IN ORDER OF ARIVAL ARE:\n");
-
for (i=0; i < 20; i++)
-
printf("%c\t", Mac1Array[i]);
-
printf("THE VALUES IN MACHING TWO IN ORDER OF ARIVAL ARE:\n");
-
for (i=0; i < 20; i++)
-
printf("%c\t", Mac2Array[i]);
-
printf("THE VALUES IN MACHING THREE IN ORDER OF ARIVAL ARE:\n");
-
for (i=0; i < 20; i++)
-
printf("%c\t", Mac3Array[i]);
-
printf("THE VALUES IN MACHING FOUR IN ORDER OF ARIVAL ARE:\n");
-
for (i=0; i < 20; i++)
-
printf("%c\t", Mac4Array[i]);
-
-
return 0;
-
}
-
-
-
-
int main(void)
-
{
-
InputSelector();
-
return 0;
-
}
aRSG is a local variable. As such, it will be destroyed whn you leave te first function. To preserve it, allocate te array on heap using malloc(). Then have the function either a) return the array address or b) have a second argument tha is the address of a pointer of the array type. The first function can then place the address of the array in th pointer address passed in.
You will also need a companion variable that contains the number of elements. This companion is passed around as needed. In C, when you only know the array address, the array appears as a pointer to element 0 and the number of elements is lost. This is called decay of array and is something you need to be aware of.
1 2621
aRSG is a local variable. As such, it will be destroyed whn you leave te first function. To preserve it, allocate te array on heap using malloc(). Then have the function either a) return the array address or b) have a second argument tha is the address of a pointer of the array type. The first function can then place the address of the array in th pointer address passed in.
You will also need a companion variable that contains the number of elements. This companion is passed around as needed. In C, when you only know the array address, the array appears as a pointer to element 0 and the number of elements is lost. This is called decay of array and is something you need to be aware of.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: CES |
last post by:
All,
Sorry for the 101 question but I can't figure out how to return all of the
contents of an array to another function. I been able to figure out how to
return individual elements of the array...
|
by: BrianP |
last post by:
Hi,
I have had to invent a work-around to get past what looks like a
JavaScript bug, the malfunctioning Perl-like JavaScript array functions
including SPLICE() and UNSHIFT().
I have boiled it...
|
by: Tobias Olbort |
last post by:
Hello,
i've a outer function, which takes a params-array as a parameter. I
want to pass this array to inner function with a params-array (e. g.
string.format).
When i've passed an integer to...
|
by: Steve |
last post by:
How can I copy 5 bytes from the middle of one array to another in Managed C++?
The following code segment causes the compilation errors below:
unsigned char cResult __gc = new unsigned char __gc;...
|
by: Soumyadip Rakshit |
last post by:
I have a 2D Array of Integers A. I would like to copy it to another
array B taking each row at a time. They are both initialized as
pointers to pointers.
I would like to use something like the...
|
by: DWalker |
last post by:
VBA, as used in Excel 2000 and Excel 2003, has a function called Array.
It's commonly seen in statements like the following:
Workbooks.OpenText Filename:=ACFileName, _
StartRow:=1,...
|
by: MLH |
last post by:
How would I modify the following to achieve a 2-dimensional array?
Dim MyWeek, MyDay
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
' Return values assume lower bound set to 1...
|
by: unicorn7777777 |
last post by:
Hi,
I need a deep copy constructor for a class which contains an array for another class:
class Chessboard
{
public:
ChessSquare chessSquare;
// copy constructor needed to copy all...
|
by: =?Utf-8?B?RGFya21hbg==?= |
last post by:
Hi,
I am wondering how you multi-dimension an array function?
My declared function looks like this:
Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long,
ByVal Val3 As...
|
by: aspire |
last post by:
All,
I am trying to allocate memory to a pointer to an array in another function, but i am not getting a successful compilation. I am getting error on a line shown below in code.
------------...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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,...
| |