16x16Matrix

G

GrErlenkamp

Hello there,

i got a list of 16 "two-character" (AU,AG,UC...) elements, and now i
want to create a 16x16-Matrix with the elements of this list for the
columns and rows.
So i need to know: How can i create such a list, how can i access each
element and use this to create the matrix?
Thank you for your help

German
 
N

Nick Keighley

i got a list of 16 "two-character" (AU,AG,UC...) elements, and now i
want to create a 16x16-Matrix with the elements of this list for the
columns and rows.
So i need to know: How can i create such a list, how can i access each
element and use this to create the matrix?

so how far have you got? You could store a couple of chars like this:-

char element [2];

So is your problem arrays? Or 2d arrays or what? Have you checked
your textbook?
Thank you for your help

no problem


--
Nick Keighley
****Can anyone find the error
Yes:
Error on line 0: Lazy programmer.
(comp.lang.c++)
 
G

GrErlenkamp

so how far have you got? You could store a couple of chars like this:-
char element [2];

I think i could do it like this, but i have to do it for 16 elements,
and i hoped there is a way to use a kind of loop, like in TCL/TK

the 2d array should be no problem

i checked my book, and the only example i found was:

char name[]={'s', 'a', 'm', '\0'};

but when I try to do like this with 2 characters i got a warning message
 
N

Nick Keighley

(e-mail address removed) wrote:

please leave more context in your post.
so how far have you got? You could store a couple of chars like this:-
char element [2];

I think i could do it like this, but i have to do it for 16 elements,

I thought you wanted 16x16?
and i hoped there is a way to use a kind of loop, like in TCL/TK

a loop to do what?
the 2d array should be no problem

ok, post the code you can do
i checked my book, and the only example i found was:

char name[]={'s', 'a', 'm', '\0'};

but when I try to do like this with 2 characters i got a warning message

so you want to initialise the matrix? As you suggest this works with
chars.
You can do a similar trick with strings.

char *names [] = {"aa", "ab", "ac"};

I'm trying to avoid solving your actual problem as I suspect its
homework.
Break it down into steps. First define your matrix then worry about
initialising it.
 
H

Henryk

Here we go:

char chArray[2][2][3] = {{"11", "22"},
{"33", "44"}};

This is a 2 by 2 matrix of 3 byte long strings. Your strings need 3
bytes because of the terminating '\0'.
 
V

Vladimir S. Oka

Hello there,

i got a list of 16 "two-character" (AU,AG,UC...) elements, and now i
want to create a 16x16-Matrix with the elements of this list for the
columns and rows.
So i need to know: How can i create such a list, how can i access each
element and use this to create the matrix?
Thank you for your help

German

The way I understand your problem is that you want a 16x16 matrix where
rows and columns are addressed by AU, AG, ... thingies, and there's 16
of them. You did not specify what is to be held in the matrix, I'll
assume int, but you can pick any other type (including the ones you
define yourself).

enum my_enum (AU = 0, AG, UC /* you fill in the rest */);

int my_matrix[16][16];

It is now possible to address the elements like this:

int x = my_matrix[AU][UC];

Hope this helps. If not, then other replies in the thread might.

Cheers

Vladimir
 
V

Vladimir S. Oka

Hi everybody!

Thanks for your help, now i found a way to make it!

CU

Please quote what you're replying to...

Also, just out of interest (and in the interest of sharing), could you
let us know which of the offered solutions did you take, if any?

Cheers

Vladimir


--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
N

Nick Keighley

Henryk wrote:

CONTEXT!
Here we go:

char chArray[2][2][3] = {{"11", "22"},
{"33", "44"}};

This is a 2 by 2 matrix of 3 byte long strings.

You seem to have missed the bit where I said I was trying to avoid
answering the questions because it might be homework...
Your strings need 3 bytes because of the terminating '\0'.

are you certain of that?

char pippo [2] = "AE";
 
H

Henryk

You seem to have missed the bit where I said I was trying to avoid
answering the questions because it might be homework...

Ooops, I really missed it.
Your strings need 3 bytes because of the terminating '\0'.

are you certain of that?

char pippo [2] = "AE";

.Net dos not compile complaining array bounds overflow.

Filling in exactly 2 chars without the '\0' would need something like

char pippo[2] = {'A', 'E'};
 
J

Jordan Abel

You seem to have missed the bit where I said I was trying to avoid
answering the questions because it might be homework...

Ooops, I really missed it.
Your strings need 3 bytes because of the terminating '\0'.

are you certain of that?

char pippo [2] = "AE";

.Net dos not compile complaining array bounds overflow.

..Net is apparently not a conforming implementation. Are you sure you're
compiling it as C, rather than C++ or C#?
Filling in exactly 2 chars without the '\0' would need something like

char pippo[2] = {'A', 'E'};
 
P

pemo

Jordan said:
You seem to have missed the bit where I said I was trying to avoid
answering the questions because it might be homework...

Ooops, I really missed it.
Your strings need 3 bytes because of the terminating '\0'.

are you certain of that?

char pippo [2] = "AE";

.Net dos not compile complaining array bounds overflow.

.Net is apparently not a conforming implementation. Are you sure
you're compiling it as C, rather than C++ or C#?
Filling in exactly 2 chars without the '\0' would need something like

char pippo[2] = {'A', 'E'};

From the std ...

char s[] = "abc", t[3] = "abc";

defines "plain" char array objects s and t whose elements are initialized
with character string literals.

This declaration is identical to

char s[] = { 'a', 'b', 'c', '\0' },
t[] = { 'a', 'b', 'c' };
 
H

Henryk

.Net is apparently not a conforming implementation. Are you sure you're
compiling it as C, rather than C++ or C#?

I compiled it as C++. Is there a difference between C and C++ that I am
not aware of?
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I compiled it as C++. Is there a difference between C and C++ that I am
not aware of?

Apparently, yes.

There are differences between C and C++.
You are apparently not aware that there are differences.
Thus, there is at least one difference between C and C++ that you are not aware of.

- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFD2RroagVFX4UWr64RAgz3AJ9VaKMJL08A2dXV6VLtc4UPP9uE+wCfWVPS
kAeclowLt+V0OyGVInWu3Os=
=02Tp
-----END PGP SIGNATURE-----
 
C

Clark S. Cox III

I compiled it as C++. Is there a difference between C and C++ that I am
not aware of?

Yes, there are likely many differences between C and C++ that you are
not aware of (this being one of them).
 
K

Keith Thompson

Henryk said:
I compiled it as C++. Is there a difference between C and C++ that I am
not aware of?

I believe so. gcc compiles

char s[2] = "xy";

without error; g++ complains.
 
K

Keith Thompson

Lew Pitcher said:
Apparently, yes.

There are differences between C and C++.
You are apparently not aware that there are differences.
Thus, there is at least one difference between C and C++ that you
are not aware of.

More likely (and more charitably) Henryk is awere that there are
differences between C and C++, but wasn't aware of this particular
one. (I wasn't either.) (His real error was not compiling it as C in
the first place.)
 
R

Robert Gamble

Keith Thompson said:
More likely (and more charitably) Henryk is awere that there are
[...]

"aware" (D'oh!)

<OT>
Perhaps it's a silly question, but what does "D'oh" mean?
</OT>

"D'oh!" is the comical catch phrase of Homer Simpson, from the
long-running animated series The Simpsons. It is typically used when
Homer injures himself, realizes that he has done something stupid or
bad, or when something bad has happened to him.

Robert Gamble
 

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
474,174
Messages
2,570,940
Members
47,484
Latest member
JackRichard

Latest Threads

Top