ポインタを宣言した後、ポインタを設定します。次に、ポインターに含まれている値をその関数に渡すことを期待して、別の関数のパラメーターにポインターを含めます。何らかの理由でこれがうまくいかないのですが、誰かが私を助けてくれますか?
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?
}