在我声明一个指针后,我设置了一个指针。然后我将指针包含在另一个函数的参数中,希望将指针中包含的值传递给该函数。由于某种原因,这不起作用,有人可以帮助我吗?
int main()
{
int *ptr1, *ptr2, count1 = 0, count2 = 0;
ptr1 = &count1;
ptr2 = &count2; //sets up the pointees
records(ptr1, ptr2, filename);
printf("%d %d\n", count1, count2);//after the loop in the function records, count1 should hold the value 43 and count2 15, however I don't think I passed the values back to main correctly because this print statement prints 0 both count1 and count2
return 0;
}
FILE* records(int* ptr1, int *ptr2, const char* filename)
{
FILE* fp;
int count1 = 0, count2 = 0
while()//omitted because not really relevant to my question
printf("%d %d\n", count1, count2)//when I compile the program, count1 is 43 and count2 is 15
return fp;
}
void initialize(int *ptr1, int *ptr2)
{
printf("%d %d", count1, count2);//for some reason the values 43 and 15 are not printed? I thought I had included the pointers in the parameters, so the values should pass?
}