-1

I am currently getting this compile-time warning:

warning: assignment makes pointer from integer without a cast

for the following line of code:

char* msg = my_vect2str(argv[3]);

Please note, my my_vect2str function has the return type char* as seen in the declaration:

char* my_vect2str(char** x);

And obviously, by the common standard, argv is defined as char** argv.

I'm not quite sure why this issue is occurring.

sampleton
  • 55
  • 7

3 Answers3

2

warning: assignment makes pointer from integer without a cast

Most likely you are calling my_vect2str() without having given a prototype to it before calling it. So as the compiler does not know what my_vect2str() returns, it assumes int, though the above error message.

alk
  • 69,737
  • 10
  • 105
  • 255
1

I think you want your vector to be like this:

char* my_vect2str(char* x);

Your return type is fine, but in your call, argv[3] will return a de-referenced value. char** implies "array of pointers" which doesn't make sense from the way you called it.

Lawrence Aiello
  • 4,560
  • 5
  • 21
  • 35
  • The my_vect2str is supposed to take an array of strings and then return the strings separated by a space. Sorry that I forgot to include that information. – sampleton Nov 13 '15 at 21:56
  • The answer does not refer to the warning: "*`assignment makes pointer from integer without a cast`*" – alk Nov 13 '15 at 22:53
0

my_vect2str expects an array of strings, but you're just passing a single string. You can do:

char *msg = my_vect2str(argv);

to pass the entire argv array. If you just want to pass argv[3], you can make another array that contains it:

char *new_array[] = { argv[3], NULL };
char *msg = my_vect2str(new_array);

I'm assuming that my_vect2str expects the array to have a NULL terminator, since the function doesn't take the length as an argument.

Barmar
  • 741,623
  • 53
  • 500
  • 612