Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Diving into C

Name: Edward 2005-06-10 3:11

Hello people.

Quick question for you pedagogues out there...

I'm planning on learning some C as an introductory language, having done just a bit of basic and html in my youth, and having knowledge of algorithms from mathematics.

Does anyone have any pointers to some good books or sites for C (books preferred)?
By "good" I mean neophyte-friendly and easy to read.

Name: Anonymous 2005-06-26 22:37

Okay technical question. I I have:

    char a[5][5];
    char b[5][5];

How do I swap these two arrays so that `a` points to the data in `b` and vice versa?

Name: Anonymous 2005-06-26 22:37

Okay technical question. If I have:

    char a[5][5];
    char b[5][5];

How do I swap these two arrays so that `a` points to the data in `b` and vice versa?

Name: Anonymous 2005-06-26 23:24

>>21 I'm sure I"m wrong; but i would come up with a third array (c) and swap the contents of b into it using a for loop, then swap the contents of a into b in a second loop, then finally use a third loop to swap the contents of c into a.

Again, I'm a noob and I'm sure there's a much more efficent way of doing this; but that's how *I* would do it (knowing what I know now).

Name: Anonymous 2005-06-27 2:13

Too much work. They're just pointers:

char *p = a;
a = b;
b = p;

Name: Anonymous 2005-06-27 20:52

>>24
foo.c:7: warning: initialization from incompatible pointer type
foo.c:8: error: incompatible types in assignment
foo.c:9: error: incompatible types in assignment

Name: Anonymous 2005-06-27 21:18

>>25
I may be wrong but it may have to be

char **pp = a;
a = b;
b = pp;

Name: 24 2005-06-28 0:25

Sorry, I was mistaken. a and b are constants pointing to the stack, so >>23 was in fact correct.

For large arrays it might be easier and faster to allocate memory and swap the pointers instead.

Name: Anonymous 2007-09-02 14:55 ID:Heaven

lol

Name: Anonymous 2009-01-15 7:33

lol

Name: Anonymous 2009-01-15 8:14

>>5
Tell us more about this female. Have you had sex with her?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List