doyle: tardis (sex and food preparation by buffyx)
doyle ([personal profile] doyle) wrote2004-01-22 10:16 pm

(no subject)

Anybody know C-programming? Because I'm going crazy.



Basically it's supposed to take the input for a line of 1s and 0s then apply a rule to each successively generated line. It's meant to look at the cell directly above the active cell and the two cells touching that one. If they're all 1s or all 0s, the active cell is a zero, otherwise it's a 1.

For instance, if I input 0000100100

my output should be:

0000100100
0001111110
0011000011
0111100110

and so on but I'm just getting

1111111111
1111111111
1111111111
1111111111

If anybody can tell me where I'm going wrong with my sucking coding, I'll love you forever and ever. I've been working at this all day and I'm ready to kill the computer.

ETA: the code is here.

[identity profile] quinn222.livejournal.com 2004-01-22 02:29 pm (UTC)(link)
I've got tp go cook dinner but I'll have a look at it after. I know a little C.

[identity profile] quinn222.livejournal.com 2004-01-22 02:44 pm (UTC)(link)
Right off a quick look shows me youve got some bracketing problems.

The bracket usage for a multiple alternative decision is as follows-

{
function_name;

if (condition)
A=B;
else if (condition)
A=C;
else if (condition)
A=D;
else
A=E;
return (void) /* if a return is needed from the function*/
}

[identity profile] doyle_sb4.livejournal.com 2004-01-22 02:46 pm (UTC)(link)
Ooh... okay, will try and fix that. Thanks!

[identity profile] quinn222.livejournal.com 2004-01-22 03:23 pm (UTC)(link)
also -

I see you calling this function -

getch();

but I don't see the actual function defined anywhere.
ext_10190: Doctor Who's Rose smiling (Default)

[identity profile] bailunrui.livejournal.com 2004-01-22 02:34 pm (UTC)(link)
I know C++ pretty well. I'll be on AIM in about 10 minutes. :)
ext_52017: (Default)

[identity profile] janeway216.livejournal.com 2004-01-22 03:20 pm (UTC)(link)
I'll have a look at it and see if I can't beat it into shape -- while my background is in C++ (and more recently, C#), the logic's still the same.

[identity profile] doyle_sb4.livejournal.com 2004-01-22 03:22 pm (UTC)(link)
Thank you so much! There's now a more up to date version here (http://www.exitseraphim.net/doyle/codeb.txt) and the header is here. (http://www.exitseraphim.net/doyle/arrayheader.h)

[identity profile] doyle_sb4.livejournal.com 2004-01-22 03:26 pm (UTC)(link)
D'oh, the header's actually here (http://www.exitseraphim.net/doyle/arrayhead.h)
ext_52017: (Default)

[identity profile] janeway216.livejournal.com 2004-01-22 04:23 pm (UTC)(link)
I've spotted it.

Here's your problem.

if ((matrix[j][0]=1)&&(matrix[j][1]=1))

Darling . . . you do realize that the equivalence operator in C is ==? = is the assignment operator.
ext_52017: (Default)

[identity profile] janeway216.livejournal.com 2004-01-22 04:25 pm (UTC)(link)
Let me make that a little clearer.

The assignment operator is a single =

The equivalency operator (which isn't its actual name, but I can't think of the real one) is ==

[identity profile] doyle_sb4.livejournal.com 2004-01-22 04:27 pm (UTC)(link)
Oh, it's nearly working! Going crazy in line 3 but the first bit's okay now *g* You rock.
ext_52017: (Default)

[identity profile] janeway216.livejournal.com 2004-01-22 08:14 pm (UTC)(link)
After having loaded it into my compiler and banged on it a while, I have a version that works. Or at least, it produces the sample result, which does not necessarily mean that it works. Anyway, here. (http://www.janeway216.com/doylecode.txt)

[identity profile] doyle_sb4.livejournal.com 2004-01-23 10:17 am (UTC)(link)
:glomps you:

You are so my new favourite person. Thankyouthankyouthankyou!

Now off to wrestle with turning the 1s and 0s into graphics *g*