I am beginner... can somebody help me/or explain how to do this. I am struggling with pointers...
In main program I declare array of characters (or pointer to array)...
Then I have function to which I pass size of the array. I malloc the space and then I populate array.
I return success or false (depend of malloc) and in main part I print the whole array.
Here is my pseudo code:
It's a junk, but I think you will get idea what I want to learn...
Thanks
In main program I declare array of characters (or pointer to array)...
Then I have function to which I pass size of the array. I malloc the space and then I populate array.
I return success or false (depend of malloc) and in main part I print the whole array.
Here is my pseudo code:
Code:
int main {
...
char *myarray;
int size = 2;
int result = populateArr(size, myarray);
for (n = 0; n < 3; n++)
printf("%s", myarray);
...
}
int populateArr(int size, myarray) {
myarray = malloc(size * sizeof(char))
*myarray="a";
*myarray++;
*myarray="b";
myarray = realloc(myarray, size + 1 * sizeof(char))
*myarray++;
*myarray="c";
}
It's a junk, but I think you will get idea what I want to learn...
Thanks