I would like to ask question regarding pointers. I dont know what to do here, I have a method in the main that is calling a method outside the main, and I need to use pointers.Basically this is the rough draft of it: Thanks!
char *book[] = { "x", "y", "z",};
int number[] = { 1, 2, 3};
struct data{ char *bookname; int booknumber;};
struct data *list[3];
my_method(char *x, int y, int *z)
{
//creating a new struct
list[(*z)++] = (struct data*) malloc( sizeof(struct data) );
//assigning arguments
list[(*z)++]->bookname = x;
list[(*z)++]->booknumber = y;
(*z)++;
}
int main()
{
int nextValue = 0;
my_method(book[nextValue], book[nextValue], &nextValue);
int i;
for(i = 0; i < 3; i++)
{
function(book[i], number[i]);
printf("name: %c number: %d", list[i]->bookname, list[i]->booknumber);
}
}
It looks like you are passing the wrong arguments to your method. Try changing the following line:
In addition, in your method you seem to be incrementing z four times, which I doubt is the behavior you want. You should only increment it once at the end, like the following: