Several malloc questions:
1. How I do malloc for this:
char *mystr[1];
(In my program *mystr is part of structure)
I want durring execution to increase (malloc) number of array elements to 5. and allocate enough space so I can have strings up to 5 characters.
Something like this:
mystr[0]="abcde";
mystr[1]="12345";
mystr[2]="fghij";
mystr[3]="aa";
mystr[4]="bb";
When I type above lines into program and compile it it's usually working fine, but when I don't know string values (I am reading them from external file) I get strange results. That's telling me that I don't know how to properly do malloc.
2. or malloc for this:
char mystr[1][1];
how to malloc this to have space for, let's say, mystr[5][5]
3. Let's say I have structure
struct list {
int counter;
char *mystr[1];
};
When I do malloc I need only to think about *mystr since it's only element of the structure whose size will change?
Thanks.
1. How I do malloc for this:
char *mystr[1];
(In my program *mystr is part of structure)
I want durring execution to increase (malloc) number of array elements to 5. and allocate enough space so I can have strings up to 5 characters.
Something like this:
mystr[0]="abcde";
mystr[1]="12345";
mystr[2]="fghij";
mystr[3]="aa";
mystr[4]="bb";
When I type above lines into program and compile it it's usually working fine, but when I don't know string values (I am reading them from external file) I get strange results. That's telling me that I don't know how to properly do malloc.
2. or malloc for this:
char mystr[1][1];
how to malloc this to have space for, let's say, mystr[5][5]
3. Let's say I have structure
struct list {
int counter;
char *mystr[1];
};
When I do malloc I need only to think about *mystr since it's only element of the structure whose size will change?
Thanks.