Help with dd array

S

Singleton

what is wrong with my main fn?



void f(char** p)

{

printf("%s", p[0]);

}



void main()

{

char a[50][50];

strcpy(a[0], "hello");

f(a);

}
 
P

pemo

Singleton said:
what is wrong with my main fn?



void f(char** p)

{

printf("%s", p[0]);

}



void main()

{

char a[50][50];

strcpy(a[0], "hello");

f(a);

}

Gosh, it's hard to know where to start ... but maybe you could say something
about what you expect this to be doing?

Something like this ...??

#include <stdlib.h>

void f(char * p)

{
printf("%c", p[0]);
}



int main(void)

{
char a[50][50];

a[0][0] = 'e';

f(&a[0][0]);
}

a is an array of 50 arrays of 50 characters. Is that what you thought it
was?
 
R

Richard Heathfield

Singleton said:
what is wrong with my main fn?



void f(char** p)

{

printf("%s", p[0]);

Undefined behaviour - calling a variadic function without a function
prototype in scope. You forgot to #include said:
}



void main()

In C, main() returns int.
{

char a[50][50];

strcpy(a[0], "hello");

You'll want said:

f takes char **, but you're not passing a char **. In a value context, the
name of an array decays into a pointer to its first element, so a has the
type char (*)[50], which is not the same as char **.
 

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

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top