Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > string assign to multi-dimension array w/o using pointer.

Reply
Thread Tools

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

 
 
Makiyo
Guest
Posts: n/a
 
      02-22-2004
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 ; )
 
Reply With Quote
 
 
 
 
David Rubin
Guest
Posts: n/a
 
      02-22-2004
Makiyo wrote:
> 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

--
"As a scientist, Throckmorton knew that if he were ever to break wind in
the echo chamber, he would never hear the end of it."

 
Reply With Quote
 
 
 
 
Russell Hanneken
Guest
Posts: n/a
 
      02-22-2004
Makiyo wrote:
> 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 */


--
Russell Hanneken
http://www.velocityreviews.com/forums/(E-Mail Removed)
Remove the 'g' from my address to send me mail.
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      02-22-2004
Makiyo wrote:

> 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).

--
Richard Heathfield : (E-Mail Removed)
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
assign the array returned by String.split to a variable Catsquotl Ruby 4 06-03-2009 07:28 PM
C - using malloc to dynamically assign memory for a array of strings Soapbar C Programming 0 11-02-2008 07:38 PM
assign constant string to BYTE array Orange C Programming 5 07-12-2006 04:17 PM
'System.String[]' from its string representation 'String[] Array' =?Utf-8?B?UmFqZXNoIHNvbmk=?= ASP .Net 0 05-04-2006 04:29 PM
Can't assign values to array Buddy Ackerman ASP .Net 6 12-19-2004 10:50 PM



Advertisments