Originally Posted by
GL.Sam
Don't ever try to allocate anything being in a struct block. And if you use array notation [] in there, it shouldn't be empty. It goes smt like following:
Code:
#include <stdio.h>
#include <string.h>
#define PROB_ENTRIES 10
struct input
{
char *problem[PROB_ENTRIES];
};
int main(void)
{
struct input huh;
int i;
for (i = 0; i < PROB_ENTRIES; i++)
{
huh.problem[i] = (char*) malloc(32 * sizeof(char));
strcpy(huh.problem[i], "What?");
printf("%s\n", huh.problem[i]);
}
return 0;
}
Hi again Sam,
I wrote a *.h file that contains my struct, and the definition of the function that uses the struct elements, and the corresponding READ_INPUT.c file and main calling READ_INPUT()
1) READ_INPUT.h:
Code:
//Struct for the Boundary condition codes and values:
typedef struct struct_bc
{
unsigned int nbdy_nodes; // Number of boundary nodes
unsigned int *NODE; // Node index number
unsigned int *BDY_CODE; // Array of the boundary codes
float *BDY_VALUES; // Array of boundary values: size [nbdy_nodes]x[nvariables]
}bc ; //bc as Boundary Conditions
void READ_BC(char *bdy_file, bc *BDYCS);
2) READ_INPUT.c:
Code:
void READ_BC(char *bdy_file, bc *BDYCS)
{
FILE *bdyf_ID;
char header[16];
BDYCS.NODE = (unsigned int*) malloc(10 * sizeof(unsigned int *));
free(BDYCS.NODE);
return;
}
but I get the following error in compilation:
Code:
READ_INPUT.c: In function ‘READ_BC’:
READ_INPUT.c:127: error: request for member ‘NODE’ in something not a structure or union
READ_INPUT.c:151: error: request for member ‘NODE’ in something not a structure or union
make: *** [main.o] Error 1
what am I doing wrong in using the structure arrays to allocate?
thanks a lot