Hi,
I have actually (sort of) figured out how to do this. By passing wach string in the array separately to a function that accepts a string. But I actually want it to pass a whole array of char[x][y] to a function in one smack and have my loops inside the function instead. I think i have been confused by the pointers somehow.
This works, but its not exactly what I want to do:
Code:
#include <stdio.h>
void printmatrixline(char *matrix);
char first[20][21] = {
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
};
int main () {
int i;
for(i=0; i < 20; i++) {
printmatrixline(first[i]);
}
printf("\n");
}
void printmatrixline(char *matrix) {
int i;
for (i=0; i < 20; i++) {
printf("%c", matrix[i]);
}
printf("\n");
}
This is what I want to do, but it doesn't work.
Code:
#include <stdio.h>
void printmatrix(char *matrix);
char first[20][21] = {
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
};
int main () {
printmatrix(first);
printf("\n");
}
void printmatrix(char *matrix) {
int i,j;
for (i=0; i < 20; i++) {
for (j=0; j < 20; j++) {
printf("%c", matrix[i][j]);
}
}
printf("\n");
}
I can successfully pass a pointer to a string using *string but I cant pass an array of strings OR and array of an array of characters by using *array. Any help?