Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Two dimensi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 25 of 32 Topic 26121 of 26977
Post > Topic >>

Re: Two dimensional array Question

by mdh <mdeh@[EMAIL PROTECTED] > May 12, 2008 at 09:12 PM

On May 11, 8:16 pm, Richard Heathfield <r...@[EMAIL PROTECTED]
> wrote:
>
> Writing code "to figure things out" is a two-edged sword. It can
certainly
> be helpful for discovering how things *appear* to work, but it is a poor
> guide for discovering how things *must* work.


Point made and taken...thanks.


> > char arr [3][3] = {"One", "Two", "Lst"};
>
> Legal, but dangerous. Don't treat these arrays of char as if they were
> strings. They aren't.

OK..now let me show my total ignorance.

So,  can multidim char arrays ever be treated as strings and would
this then be the correct intialization? char arr[] [] = "one, two";
And, for a regular (one dim) char array,  would this be a string
intialization?  char arr[]= "something" or the use of strcpy?

And, somewhat philosophically, a (one dim)  char array is simply a
contiguous set of bytes. If one ? *knows* the array is NULL
terminated, then we can safely treat it as a string. But the *only*
way to know this is if it is correctly initialized in the first place.
Is this a fair way of looking at it?



> > p=&arr[i][j];
> > printf( "%p\n", p);
>
> Although the representations of char * and void * are required to be the
> same, it is generally wiser to insist on void * for %p:
>
>   printf("%p\n", (void *)p);

I did read today about the need for a pointer to be cast to
void ...but is there a reason for this? Other than the language says
it should be so.


>
> You fell into the trap.

Yup!

> The easiest way to comprehend multidimensional arrays is to think of
them
> as arrays of arrays. If you never try to breach the bounds of an object,
> all will be well. By treating arrays-of-arrays as if they were a single
> contiguous object (EVEN IF THAT IS TRUE), you're violating that
principle

Yes..I like it...thanks.
 




 32 Posts in Topic:
Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-08 08:16:13 
Re: Two dimensional array Question
Joe Wright <joewwright  2008-05-08 19:15:37 
Re: Two dimensional array Question
"Default User"   2008-05-08 23:24:55 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-08 21:03:36 
Re: Two dimensional array Question
"Default User"   2008-05-09 16:27:53 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-09 00:30:00 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-08 18:39:27 
Re: Two dimensional array Question
Barry Schwarz <schwarz  2008-05-08 20:54:09 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-09 06:18:51 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-09 20:35:22 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-10 07:09:06 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-10 12:42:22 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-10 08:43:58 
Re: Two dimensional array Question
Joe Wright <joewwright  2008-05-10 09:26:20 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-10 14:53:55 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-10 12:25:49 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-10 17:12:46 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-11 01:17:26 
Re: Two dimensional array Question
Barry Schwarz <schwarz  2008-05-11 04:17:57 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-11 19:07:45 
Re: Two dimensional array Question
Richard Heathfield <rj  2008-05-12 03:16:04 
Re: Two dimensional array Question
Richard Heathfield <rj  2008-05-12 03:17:11 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-12 07:18:50 
Re: Two dimensional array Question
"Default User"   2008-05-12 06:19:46 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-12 21:12:17 
Re: Two dimensional array Question
Richard Heathfield <rj  2008-05-13 04:48:22 
Re: Two dimensional array Question
Chris Torek <nospam@[E  2008-05-13 16:38:01 
Re: Two dimensional array Question
Richard Heathfield <rj  2008-05-13 16:53:43 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-12 21:13:55 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-16 22:17:14 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-12 22:26:08 
Re: Two dimensional array Question
Barry Schwarz <schwarz  2008-05-16 18:44:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:53:26 CDT 2008.