Hi there,
Im trying to create a simple program that creates an 2D array of numbers and prints them to the screen via a function. I think i have got most of the way however, I cant seem to get the print function to print correctly. It's been a while since i coded in C. Can anyone see where i have slipped up?
#include <stdio.h>
#include <stdlib.h>
#define START 0
#define MAX 128
void printarray(int *,int);
int main(int argc, char *argv[])
{
int i,j,c;
int vig[MAX][MAX];
for(i=0;i<MAX;i++)
{
c=START+i;
for(j=0;j<MAX;j++)
{
if(c<MAX) /* This section is a simple loop that initiates a Vigenère Table */
{ /* into an array called "vig". This array will be used in the */
vig[i][j]=c; /* encryption/decryption process later on. */
c++;
}
else
{
c=START;
vig[i][j]=c;
c++;
}
}
}
printarray(&vig[0][0], MAX);
system("PAUSE");
fclose(input);
return 0;
}
void printarray(int *vig1,int n)
{
int i,j,x;
int vig2[MAX][MAX];
vig1=&vig2[MAX][MAX];
for(i=0;i<MAX;i++)
{
for(j=0;j<MAX;j++)
{
printf(" %d,",vig2[i][j]);
}
printf(" \n");
}
}
Also I couldn't remember how to pass the array to the function without having to assign the pointer to a new array :
vig1=&vig2[MAX][MAX];
I didn't think you had to do this but cant get it to pass it in any other way.
Thanks for your time.
Craig