LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2010, 08:23 AM   #1
vasmakk
Member
 
Registered: Jan 2009
Distribution: Debian Lenny, Ubuntu 9.04
Posts: 87

Rep: Reputation: 16
Multi Dimensional Arrays in C of variable size - (The traditional way)


Hi to all!

I am curious if there is a way to describe and use variable sized multi-dimensional arrays in C using pointers...
I mean, for 1-dimensional array e.g. I can use the following piece of code:


...
int i , N;
int *array;

scanf("%d", &N);
array = (int*) malloc(N*sizeof(int));

for (i=0; i<N; ++i) array[i] = i; // Assigning values to the array

for (i=0; i<N; ++i) printf("%d ", array[i]); // Printing the assigned values

free (array);
...

But what about the two dimensional array[N][M] ?
I guess i have to use a double pointer e.g: int **array. But how exactly?

Note that I use C90 and not C99.


Thanks in advance
Vas ...
 
Old 04-15-2010, 09:25 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
This seemed useful:
http://www.ibiblio.org/pub/languages.../append-c.html
 
1 members found this post helpful.
Old 04-15-2010, 10:11 AM   #3
vasmakk
Member
 
Registered: Jan 2009
Distribution: Debian Lenny, Ubuntu 9.04
Posts: 87

Original Poster
Rep: Reputation: 16
Thanks !

This is indeed useful
I'll give it a try ...

Vas
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Double pointers and two dimensional arrays in C kponenation Programming 23 03-16-2011 11:43 AM
Multi-dimensional arrays in C Completely Clueless Programming 4 09-15-2009 10:51 AM
LXer: Multi-Dimensional Clustering Table Size Estimator for DB2 LXer Syndicated Linux News 0 08-24-2006 12:54 AM
error code for pointers and 2-Dimensional arrays shams Programming 1 08-06-2004 10:00 PM
Looking for a safe and efficient way to use two dimensional arrays. George2 Programming 6 03-22-2004 02:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration