namarino namarino - 5 months ago 40
C Question

Passing array in as parameter in C

I'm trying to write a function that manipulates an array directly.I don't want to return anything, so obviously I'm going to be using pointers in some fashion.

void makeGraph(some parameter) {
//manipulates array

int main() {
char graph[40][60];


I can't figure out what to pass in as parameters. Any help would be appreciated.


In C array can be passed as a pointer to its first element. The function prototype could be any of these

void makeGraph(char graph[40][60]);
void makeGraph(char graph[][60]);
void makeGraph(char (*graph)[60]);  

To call this function you can pass argument as

makeGraph(graph);  //or