M
mdh
Hi All,
Just when I thought things were going to get easy!
Structs.
I **thought** I had copied the examples pretty closely, but am getting
a number of errors.
The code:
#include <stdio.h>
int main (int argc, const char * argv[]) {
struct point {
int x;
int y;
};
struct point makepoint( int, int); /* error. previous decl of
'makepoint' was here*/
struct point p1 = makepoint(8,9);
printf("%d, %d\n", p1.x, p1.y);
}
struct point makepoint(int x, int y) {
struct point temp;
temp.x = x;
temp.y = y;
return temp;
}
The error I got in the past has meant that something has been defined
twice, but as far as I can tell, ( probably incorrectly) I have
declared a struct called point, then declared a function which accepts
two integer arguments and returns a 'point' structure. Clearly I am
missing something.
In addition, I am getting a number of errors in makepoint function
defintion, which may become obvious once my initial query is cleared.
If not, I will ask then.
Lastly, K&R say , on p 130, of the makepoint function, "notice that
there is no conflict between the argument name and the member with the
same name". I assume that this refers to the lines
temp.x = x;
temp.y = y;
Thanks as usual.
Just when I thought things were going to get easy!
Structs.
I **thought** I had copied the examples pretty closely, but am getting
a number of errors.
The code:
#include <stdio.h>
int main (int argc, const char * argv[]) {
struct point {
int x;
int y;
};
struct point makepoint( int, int); /* error. previous decl of
'makepoint' was here*/
struct point p1 = makepoint(8,9);
printf("%d, %d\n", p1.x, p1.y);
}
struct point makepoint(int x, int y) {
struct point temp;
temp.x = x;
temp.y = y;
return temp;
}
The error I got in the past has meant that something has been defined
twice, but as far as I can tell, ( probably incorrectly) I have
declared a struct called point, then declared a function which accepts
two integer arguments and returns a 'point' structure. Clearly I am
missing something.
In addition, I am getting a number of errors in makepoint function
defintion, which may become obvious once my initial query is cleared.
If not, I will ask then.
Lastly, K&R say , on p 130, of the makepoint function, "notice that
there is no conflict between the argument name and the member with the
same name". I assume that this refers to the lines
temp.x = x;
temp.y = y;
Thanks as usual.