namarino namarino - 1 year ago 85
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download