473,770 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Single dim array as a multidim array?

Please could someone tell me how to use a single-dimensional array as a
two-dimensional array? Is the following correct:

int ROW_SIZE = 5;
int COL_SIZE = 3;

int *arr = (int*) malloc(sizeof(i nt) *ROW_SIZE*COL_S IZE);

arr[i *COLUMN_SIZE + j];

will this only work for square arrays or all two-dim arrays ? Thanks :)
Sona

Jul 19 '05
10 5466
foo wrote:
Irrwahn Grausewitz <ir*****@freene t.de> wrote in message
ma*******@axter .com (foo) wrote in

a lot of semi-cryptical C++ code. Please do not cross-post
C++ stuff to c.l.c.
>Nit2: the cast to int* is superfluous in C.


And please do not cross-post your superfluous C remarks to c.l.c++


You are both at fault here, not to mention the OP (who should not
have crossposted in the first place). Both of you should have
set followups. This is the appropriate mechanism to advise
across newsgroups, and prevent further confusion.

--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
Jul 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1716
by: somaboy mx | last post by:
Hello, I need to do the following: Say I have a multidim array: $array = array(); $array = 'Kevin';
8
1912
by: Levent | last post by:
Hi, Is it possible to have static multi-dim array as a function return parameter? in particular, class Foo { int arr; public: ? getArr() {return (?) arr;}
10
1288
by: Sona | last post by:
Please could someone tell me how to use a single-dimensional array as a two-dimensional array? Is the following correct: int ROW_SIZE = 5; int COL_SIZE = 3; int *arr = (int*) malloc(sizeof(int) *ROW_SIZE*COL_SIZE); arr;
2
2099
by: Salman Khilji | last post by:
After reading all the FAQs, I cannot solve the following problem: I have a pointer of type double. I am supposed to 1) Allocate memory for it assuming that the pointer will be pointing to a multi-dimensional array whose dimensions will be specified at run-time. 2) Set the individual elements of the array using pointer-arithmetic.
1
1631
by: Abhi | last post by:
Hi! I am wondering if someone can point me to the needed sort function. There are so many of them that I simply got lost by reading their descriptions. I try to explain what I need. I have a multidimensional array and I have a function that outputs it as a table. $arr contains an array that contains usernames $arr contains an array that contains real names $arr contains an array that contains e-mails
0
1397
by: guerrerofarias | last post by:
I have a "population" of objects that is suppose to do a lot of stuff during its lifecycle... I had everything working fine (not fancy code, though) with an array, but now I've received instructions to let the population change size over generations. This means my array no longer works...I want to change it to a vector (or map), keeping the basic structure of the code. But it beats my skills...I read a thread...
1
828
by: Astha | last post by:
Hi. I am having a problem when retrieving data from database and comparing each of them to decide wheter or not to give access to a user to a certain page.Actually,the data being retrieved are checkbox values..there are four checkboxes under one category..there are six category altogether...so 24 checkboxes altogether.I have to use multidim array...i guess...bt am very confused abt it.Pls can anyone help me out!
31
1913
by: mdh | last post by:
I am still having a problem understanding K&RII on p 112. I have looked at the FAQs --which I am sure answer it in a way that I have missed, so here goes. A 2-dim array, (per K&R) is really a 1-dim array, each of whose elements is an array. Looking at the debugger I use, arr is shown as an initial value of "2", but when expanded, there are 2 consecutive arrays of 13 elements. So, may I ask this? Is there anything special that marks the...
152
9908
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { { 3.14 }, { 42.6 } }; f((double *)array, sizeof array / sizeof **array); return 0;
0
9453
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6710
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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 we have to send another system
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.