Here’s how to assign values to flexible array members added in c99.
#include <stdio.h>
typedef struct _line {
int size;
int data[];
}line;
void funfun(line * abc){
if(abc->data[0] == 1 ){
printf("You can't touch this");
}
else{
printf("MC Hammer");
}
}
To design a test so that the if branch in the code above is true, it is not possible to put a value in the usual test data entry method.
This is because it is a flexible array member.
Therefore, the value should be entered as shown below using the code before the call in the test information tab.
size_t this_length = 5;
abc = (line *)malloc (sizeof (line) + this_length);
abc->data[0] = 1;
Need more help with this?
Don’t hesitate to contact us here.