string assign to multi-dimension array w/o using pointer.

M

Makiyo

how do u do something like this
char x[3][10];
x[0][] = "hello";

I got an error,
but is there a way I can do it without using pointer?
thx ; )
 
D

David Rubin

Makiyo said:
how do u do something like this
char x[3][10];
x[0][] = "hello";

I got an error,
but is there a way I can do it without using pointer?
thx ; )

strcpy(x[0], "hello");

/david
 
R

Russell Hanneken

Makiyo said:
how do u do something like this
char x[3][10];
x[0][] = "hello";

I got an error,
but is there a way I can do it without using pointer?

I guess you're trying to do this:

char x[3][10];
strcpy(x[0], "hello");

You can also initialize the array like this:

char x[3][10] = { "hello" }; /* Because initializers are missing for
x[1] and x[2], 0 is assigned to
every element of both arrays */
 
R

Richard Heathfield

Makiyo said:
how do u do something like this
char x[3][10];
x[0][] = "hello";

I got an error,

That's because you can't assign to an array. x[0] is an array of 10 char,
and an array is not a "modifiable lvalue" (I'll spare you the details), so
you can't do what you tried to do.
but is there a way I can do it without using pointer?

No. Any attempt to load x[0] involves using a pointer, although I'll agree
that it doesn't always /look/ like it. This is because of The Rule.

strcpy(x[0], "hello"); will work fine, for example, but it does actually use
a pointer (because of The Rule).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top