tutorial6 - To scan values using a function, we have to set...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
To scan values using a function, we have to set the input type as pointer type [void readFrac (struct Frac *f)], and the input to call the function is the address of the variable [readFrac(&f)] and the address of each part of the structure is address of what the pointer is pointing to, [scanf(“%d/%d”, &((*f).num), &((*f).den)]. &((*f).num) is BUT &(f.num) = &((*f).num) = f.num in this case, because both input for the main function and readFrac functions have the same name. the &(f.num) is from the main function and the f.num is the readFrac function.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Function swap: input type is pointer type [void swap (int *, int *)] 11 , input to call the function is address 51 Function reduce: input type is pointer type [void reduce (struct Frac *)] 13 , input to call the function is address 20 . In the function, everything is input into the address of the variable itself, since return void 63 -> everything input using pointers [int gcd1 = gcd (((*f).num), ((*f).den)); (*f).num /= gcd1; (*f).den /= gcd1;] 65
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/09/2012 for the course ELECTRICAL 1221 taught by Professor Tan during the Spring '11 term at National University of Singapore.

Page1 / 5

tutorial6 - To scan values using a function, we have to set...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online