multidimensional arrays as function parameter

S

Salmen

hello,

i have problems passing a 2-dimensional array of char to a function. The
source below is generating an error.
So does anybody know, which mistake I made?

void myfkt(char** ppWord){
long i,j;
for(i=0;i<4;i++){
for(j=0;j<6;j++){
putchar(ppWord[j]);
}
}
}

void main(void){
long i;
char word[4][6]={{"hallo"},{"\n\r"},{"hallo"},{"\n\r"}};
myfkt(word);
}
 
A

Al Bowers

Salmen said:
hello,

i have problems passing a 2-dimensional array of char to a function. The
source below is generating an error.
So does anybody know, which mistake I made?

void myfkt(char** ppWord){
long i,j;
for(i=0;i<4;i++){
for(j=0;j<6;j++){
putchar(ppWord[j]);
}
}
}


protype the function
void myfkt(char ppWord[][6]);
void main(void){ int main(void)
long i;
char word[4][6]={{"hallo"},{"\n\r"},{"hallo"},{"\n\r"}};
myfkt(word);
}

#include <stdio.h>

void myfkt(char ppWord[][6])
{
long i;

for(i=0;i<4;i++)
printf("%s",ppWord);
}

int main(void)
{
char word[4][6]={{"hallo"},{"\n"},{"hallo"},{"\n"}};

myfkt(word);
return 0;
}
 
M

Mark A. Odell

i have problems passing a 2-dimensional array of char to a function.
The source below is generating an error.
So does anybody know, which mistake I made?

void myfkt(char** ppWord){
long i,j;
for(i=0;i<4;i++){
for(j=0;j<6;j++){
putchar(ppWord[j]);
}
}
}


protype the function
void myfkt(char ppWord[][6]);


Just avoid the temptation to use sizeof on ppWord.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top