473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

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 ; )
Nov 14 '05 #1
3 1530
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."

Nov 14 '05 #2
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
rg********@pobox.com
Remove the 'g' from my address to send me mail.
Nov 14 '05 #3
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 : bi****@eton.powernet.co.uk
"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
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian | last post by:
Hello, I am trying to work out how to have smarty use a string's contents as the display-> template.. ie: $smarty->display($buffer); obviously $buffer isn't a filename, but a smarty template...
1
by: JVarsoke | last post by:
I'm trying to use pgpenvelope and I keep getting the message: Can't locate loadable object for module String::Approx in @INC (@INC contains: /usr/lib/perl5/5.8.0/i586-linux-thread-multi . . . ...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
5
by: derrick | last post by:
I used to program text RPG's in C back in high school, but I was very crude at it and only learned what I needed to get the job done. I am now about to graduate college with a degree in English and...
2
by: | last post by:
I need to assign a multiline string to a textbox in design time, my problem is that strings cannot be on more than one line in the editor, even the _ at the end of a line doesn't work with string,...
1
by: fakeprogress | last post by:
I am attempting to write a function (I shall call it findcode()) that makes sure that a code read in from a file is an actual code, one found within the library of books. Here is what I have:...
1
by: syntego | last post by:
I am using DB2 V8 fixpack 10 and have the following issue: >From a User Defined Function, I can assign multiple variables in a single statement as follows: -- Get the first update transaction...
8
by: Ashish Khandelwal | last post by:
-----See below code, string str = "blair"; string strValue = "ABC"; string str1 = "brainlessness"; string strValue1 = "XYZ"; int hash = str.GetHashCode() ; // Returns 175803953 int hash1 =...
16
by: maehhheeyy | last post by:
this is stopping my program from running properly. is there something wrong in my code when that happens?
3
by: 6afraidbecause789 | last post by:
If able, can someone please help make a Where clause that strings together IDs in a multi-select listbox AND includes a date range. I wasn’t thinking when I used the code below that strings...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.