473,322 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How can I create an array of pointers C from 2 Arrays of Pointers?

int main() { //

int *A, *B, *C; //Arrays of pointers
int i , j , k ;
int nA, nB, nC; //Arrays size

printf("Type the arrays size (A and B): \n");
scanf("%d %d", &nA, &nB);

nC = nA + nB;

A = (int *)malloc(sizeof(int) * nA);
B = (int *)malloc(sizeof(int) * nB);
C = (int *)malloc(sizeof(int) * nC);

srand((int)time((time_t *)NULL));

for(i = 0; i < nA; i++) {
A[i] = rand() % 99;
}

for(j = 0; j<nB; j++) {
B[j] = rand() % 99;
}

k = 0;
while (k < nC) {
if(k < nB) {
C[k] = A[k];
} else {
C[k] = B[k];
}
printf("C[%d] = %d\n", k, C[k], nC);
k++;
}
}
Oct 13 '17 #1
1 1777
weaknessforcats
9,208 Expert Mod 8TB
This array C is what is called a 2-dimensional array.

Read this and post me again if you still have questions.

https://bytes.com/topic/c/insights/7...rrays-revealed
Oct 13 '17 #2

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

Similar topics

6
by: Bart Nessux | last post by:
How is this done in php? I've tried several variations of the following: contact_array = ($_POST, $_POST, $_POST, $_POST, $_POST); The ultimate goal is to insert the array into a table in...
1
by: Richard Hayden | last post by:
Hi, I understand such pointers as 'const int* const ip' and 'const int* ip' etc., but I'm getting confused when seeing things like 'const int* const* ip' (i.e. with two or more asterisks)....
19
by: gaga | last post by:
I can't seem to get this to work: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *names; char **np;
0
by: hazz | last post by:
i have an array (or collection if necessary) of Customers with CustomerID and several properties. For each of these Customers I will have a one to many relationship with Customer products....
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
5
by: M. Fisher | last post by:
Pardon my ignorance here... I have created arrays such as: var SDET_Lab130= new Array(); SDET_Lab130 = new Array(); SDET_Lab130 = ; SDET_Lab130 = ; SDET_Lab130 = ; SDET_Lab130 = ;...
64
by: Zytan | last post by:
I know there are no pointers in C#, but if you do: a = b; and a and b are both arrays, they now both point to the same memory (changing one changes the other). So, it makes them seem like...
6
by: M Turo | last post by:
Hi, I was wondering if anyone can help. I'm want to pre-load a 'table' of function pointers that I can call using a its arrayed index, eg (non c code example) pFunc = func_A; pFunc = func_B;
5
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories shown by differnent radio buttons, on the click of...
8
by: a | last post by:
Hello. Suppose I have a family of functions f_0(x) = 0*x f_1(x) = 1*x .... f_n(x) = n*x taking float and returning float (naturally, the actual functions would
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.