My C code
#include <stdio.h>
#include <stdlib.h>
#include "help.h"
int test(int x, P *ut) {
int point = 10;
ut->dt[10].max_x = NULL;
}
int main(int argc, char** argv) {
return (EXIT_SUCCESS);
}
my help.h file code
typedef struct{
double max_x;
double max_y;
}X;
typedef struct{
X dt[10];
}P;
I got an error i.e
error: incompatible types in assignment
error comes in here
ut->dt[10].max_x = NULL;
can anybody help me. thanks in开发者_开发问答 advance.
You are trying to set a double value to NULL
, which even if compiles, is mixing two incompatible terms. (In some versions of the C class library NULL
is defined simply as 0
, in others as (void*)0
- in latter case you get an error for such code.)
Moreover, you try to access index 10 of an array of size 10, which is out of bounds - the elements are indexed from 0 to 9. So try this:
ut->dt[9].max_x = 0.0;
I can see two problems in
ut->dt[10].max_x = NULL;
- The index
10
is not valid, it should be 0-9 - You are assigning a
NULL
value to a double. I guess you meant0.0
.
max_x is of type double, NULL is of type (void *). What makes you think they are compatible?
Try
ut->dt[10].max_x = 0.0;
Accessing dt[10] is out of bounds, array indexing starts at 0!
精彩评论