Hi there everyone, i've just joined the forum as i'm teaching myself c in my lunch hour at work and i'm sick of getting frustrated!
I've set myself a problem to tackle and i'm going to try and get a working solution and as i learn more, maybe optimise the code a bit as no doubt it will be quite crude.
I've hit a sticking point with a 2 dimensional array.
Basically i want to have a 9x9 matrix or array which looks like this:
012345678
012345678
012345678
012345678
012345678
012345678
012345678
012345678
012345678
Obviously my code is pretty crude but i'm just learning!
Code:
#include <stdio.h>
int main()
{
// **********************
//initialise variables
int originalarray[8][8]; // 9x9 matrix
int x, y, c;
//***********************
for (x = 0; x <= 8; x++) // Goes through rows
{
for (y = 0; y <= 8; y++) //Goes through columns
{
//scanf( "%d", &c ); // reads character input
originalarray[x][y] = y; // makes the integer value of the matrix equal to the column number
}
}
for (x = 0; x <= 8; x = x++) //Goes through rows
{ printf("\n"); //print newline
for (y = 0; y <= 8; y = y++) //Goes through columns
{
printf("%d", originalarray[x][y]); // prints each value of the matrix in turn
}
}
}
So thats my code, the scanf bit is commented out as i was originally going to read in from the keyboard but i was trying to make it simlpler because it is failing.
Anyway, my output is this:
(don't know if i should put this in code tags)
Code:
012345670
012345670
012345670
012345670
012345670
012345670
012345670
012345670
Segmentation fault (core dumped)
As you can see there are only 8 rows and the end column is just zeros!
I would be very grateful if anyone could help here. Maybe i'll post the rest of my little problem up as i get more done so you can laugh at me and/or help optimise my code!
Thank you in advance for your time.
Simon.