[comp.lang.c] Arrays and stuff

jdb@reef.cis.ufl.edu (Brian K. W. Hook) (02/14/91)

I just searched the FAQ for this one, but basically just look at the
example and see if you know of a way around this:

Basically, you can initialize an array with values, and you can't
re-initialize after declaration.  However, if I wanted to put a string into
an array I could use strcpy(), but I want to fill in the entire array with
a predefined array: in effect:


char array[NUMBER][SIZE];

array[number]={ ...assorted values...};

How do I do this?  I want different bitmasks for a cursor depending on what
the user does, but I can't seem to implement this very easily unless
I use:

char *mask;

mask=&array[0][0];

or

strcpy(mask,array[0]);


But this is a pain for certain things that I am doing.  And I DEFINITELY
don't want to do:

array[0][0]=0x44;
array[0][1]=0x99;

etc. etc. 

This is the way I do it right now since it offers some flexibility....but
it is SOOOOOOO ugly.

Brian

browns@iccgcc.decnet.ab.com (Stan Brown) (02/16/91)

In article <26915@uflorida.cis.ufl.EDU>, jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
> Basically, you can initialize an array with values, and you can't
> re-initialize after declaration.  However, if I wanted to put a string into
> an array I could use strcpy(), but I want to fill in the entire array with
> a predefined array: in effect:
>      char array[NUMBER][SIZE];
>      array[number]={ ...assorted values...};
> How do I do this?  I want different bitmasks for a cursor depending on what
> the user does, but I can't seem to implement this very easily unless
> I use:
>      char *mask;
>      mask=&array[0][0];
> or
>      strcpy(mask,array[0]);
> But this is a pain for certain things that I am doing.  And I DEFINITELY
> don't want to do:
>      array[0][0]=0x44;
>      array[0][1]=0x99;
> etc. etc. 

Use memcpy not strcpy:
	memcpy(array[n], mask, SIZE);
will copy SIZE bytes from mask to array[n].

memcpy is declared in <string.h>

Hey--this is all my opinion, nobody else's. Rely on it at your peril.
"no yucky green things"            email: browns@iccgcc.decnet.ab.com
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA    +1 216 371 0043