-5

This part of my code:

    char MAC_ADRESSES[MAX_LINES][100];
    for(j=i+1; j<=countlines; j++)
        {
            if((MAC_ADRESSES[j])==(MAC_ADRESSES[i]))
            {
                MAC_ADRESSES[j] = NULL;
            }

At the point where I want to change the string with a NULL I have a compiler error about incompatible types assignment. Do not understand why..

7
  • 5
    What's the definition of MAC_ADRESSES?
    – Carl Norum
    Sep 11, 2013 at 17:56
  • 3
    English is not a context-free language. "mistake" is a synonym for "error" but a "compiler mistake" is not the same as a "compiler error".
    – user529758
    Sep 11, 2013 at 17:58
  • Sorry I edited it. Yes I've got a compiler error. char MAC_ADRESSES[MAX_LINES][100] Sep 11, 2013 at 17:59
  • Why you are not using MAC_ADRESSES[j] = '0' ?
    – haccks
    Sep 11, 2013 at 17:59
  • 3
    Since the error message is about incompatible types, why did you think that telling us the type of MAC_ADRESSES (sic) would be irrelevant to figuring out the cause of the problem?
    – Jim Balter
    Sep 11, 2013 at 18:01

5 Answers 5

2

Presumably MAC_ADRESSES is not an array of pointers. NULL is a pointer (normally (void *)0 in C), so you can't assign it to a non-pointer variable.

Edit: Since your definition is char MAC_ADRESSES[MAX_LINES][100], you have a 2D array, not an array of pointers. You can't store NULL in this array. You can wipe out a string by putting a null character in the first byte, though:

            MAC_ADRESSES[j][0] = '\0';

Note that you can't test strings for equality using ==, either. You should be using strcmp.

1

I think you need this

for(j=i+1; j<=countlines; j++)
    {
        if(strcmp(MAC_ADRESSES[j],MAC_ADRESSES[i]) == 0)
        {
            MAC_ADRESSES[j][0] = 0;
        }
    }

Given that

char MAC_ADRESSES[MAX_LINES][100]

As I guess you are trying to remove duplicates

BTW MAC_ADDRESS[j] is an array - not a pointer! Hence == operator will not make any sense

1

NULL is defined something like below

#define NULL (void*)0

So you can't assign void* type to char[][].(both are incompatible types)

If you want to invalidate use '\0' or 0;

MAC_ADRESSES[j][0] = '\0';

      (or)

MAC_ADRESSES[j][0] = 0;

(Note: Also you should use strcmp / stricmp / strcasecmp to compare the c string & == is not allowed on array bases)

1

Instead of NULL use '\0'

NULL is macros defined as

#define NULL (void *)0

or

#define NULL 0 , hence the

warning: assignment makes integer from pointer without a cast

As per your edited question use:

MAC_ADRESSES[j][0] = '\0';

2
  • because you're trying to assign a value to an array, as Carl Norum points out. Sep 11, 2013 at 18:06
  • @same error ? If you've char MAC_ADRESSES[MAX_LINES][100] Obviously MAC_ADRESSES[j] = NULL; is not valid use MAC_ADRESSES[j][0] = '\0';
    – P0W
    Sep 11, 2013 at 18:08
0

if MAC_ADRESSES isn't a pointer array then MAC_ADRESSES[j] = NULL; is wrong because NULL is a pointer and MAC_ADRESSES is not

Not the answer you're looking for? Browse other questions tagged or ask your own question.