I wrote like this but it isn't work
example is int. how can I do this??Code:(const *)example;
I wrote like this but it isn't work
example is int. how can I do this??Code:(const *)example;
shoud be just
since its your not coverting into const integer pointer.Code:(const int) example;
ssharish
it isnt work! I have simple struct and I want to use like this
but "x[bla]" you now bla must be const int so I get error..Code:void example(int *vle) { ..... struct exam{ ...... }x[(const)*vle] }
sory my english.
I used it (const int) but result didnt change...
I get this error
1)Constant expression required
2)Constant variable 'x' must be initialized
I suppose you are trying to create an array of structs with a non-constant expression. This is illegal.
Consider:
It is allowed to create a dynamic array on the stack in C99, but not C89.Code:int n = 10; int myarray[n]; /* Illegal */ int myarray[10]; /* Legal */
But I must get struct size from another result.. Cant we do this?? :S
thanks for advice but I didnt it in struct.. if I use int so I can do like this:
is it true?? I think yes but I never do it for struct.. How can we do this??Code:int * number = (int *) malloc(*nos);
Should be
You need to specifgy the size to the malloc, otherwise the malloc will assume one byte for every element, which in your case should be int. Since you are trying to allocate integer vector. In the same way if you are allocating float then just replace sizeof(int) with sizof(float) and same applies for the other datatypes.Code:int * number = (int *) malloc( *nos * sizeof(int) ); and check for error if( number == NULL ) report error;
ssharish
Yes :S but I want it for struct like this
I want to use malloc for x struct??Code:void example(int *vle) { ..... struct exam{ ...... }x }
and add one more question how can we do this for char array??
Last edited by koyboy; 05-24-2008 at 04:40 PM.
ssharishCode:void example(int *vle) { ..... struct exam{ int in; float flo; }; struct exam *container = malloc( sizeof( struct exam ) * *vle ); // Check for return value of malloc and report error on failure. }