-3

EXPLANATION:

simply trying to convert a a char to hexadecimal but i keep getting this error and I'm not sure how to get around this

PROBLEM:

warning: passing argument 1 of ‘strtol’ makes pointer from integer without a cast[cs214111@cs lab3]$ vi lab3.c

CODE:

void print_group(char array[])
{
    int num,a;
    char ch[10];

    printf("here ");    
    for (a = 0 ; a < 8 ; a++)
    {
        strcpy(ch,array[3]);  
        num = strtol(ch,0,16);//------------------THIS IS IT//
        printf("%i",num);
    }   
}
cmehmen
  • 249
  • 1
  • 3
  • 12
  • 2
    `array[3]` is not an address. – Sourav Ghosh Sep 27 '15 at 20:12
  • 2
    What is it about the error that you find ambiguous? You are passing an integer (a char is a type of integer) as the first argument to strtol instead of a pointer. Don't do that. – William Pursell Sep 27 '15 at 20:14
  • use either `array + 3` or use `&array[3]` for the second argument. The second argument needs to be a `char *` or char pointer and you are passing a `char` instead. And this `char` in turn is being promoted to an integer. Do you have an `#include ` in your file in order to declare a prototype for the `strcpy()` function? – Richard Chambers Sep 27 '15 at 20:15

1 Answers1

1

You are passing char where char * is expected, maybe

strcpy(ch, &array[3]);

But from your code it would seem like this, is what you actually need

num = strtol(&array[3], 0, 16);

if strcpy() works in this case, then this will work.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97