I don't understand....
why this doesn't work...
I've got the following code snippet. I'm using the book" Teach yourself C for Linux Programming in 21 days" . On page 262-263, it has a rather simple program to demonstrate passing a structure as a function argument. Typing in the example, it worked fine. So I thought I'd experiment with pointers and structures. Typing in the following code, I don't understand why I keep getting errors.
#include <stdio.h>
struct data {
float amount;
char fname[30];
char lname[30];
};/*This is where I modified it, it used to create an instance*/
void print_rec(struct data x);
struct data rec; /*creating instance of data named rec */
struct data *p_data; /*declaration of pointer p_data for data I believe, this is my line*/
printf("%lu",(unsigned long)p_data); /*what I thought would display the address supposedly stored in p_data, but I get an error instead */
If I Remark out that last like, the program works correctly, if I unremark it, I get the error:"Parse error before string constant"
I'm using GCC 3.2.2-5 if it matters.
In the previous example, it looks to me like they did the same exact thing and it came out correctly. If I need to enter the full code for the example I'm working on, or the code for the previous example I'm trying to base this one on, let me know. This isn't a homework assignment. I'm just trying to teach myself how to use C.
Any help would be appreciated, since I can't figure out what I'm doing wrong with such a simple section of code....
I've got the following code snippet. I'm using the book" Teach yourself C for Linux Programming in 21 days" . On page 262-263, it has a rather simple program to demonstrate passing a structure as a function argument. Typing in the example, it worked fine. So I thought I'd experiment with pointers and structures. Typing in the following code, I don't understand why I keep getting errors.
#include <stdio.h>
struct data {
float amount;
char fname[30];
char lname[30];
};/*This is where I modified it, it used to create an instance*/
void print_rec(struct data x);
struct data rec; /*creating instance of data named rec */
struct data *p_data; /*declaration of pointer p_data for data I believe, this is my line*/
printf("%lu",(unsigned long)p_data); /*what I thought would display the address supposedly stored in p_data, but I get an error instead */
If I Remark out that last like, the program works correctly, if I unremark it, I get the error:"Parse error before string constant"
I'm using GCC 3.2.2-5 if it matters.
In the previous example, it looks to me like they did the same exact thing and it came out correctly. If I need to enter the full code for the example I'm working on, or the code for the previous example I'm trying to base this one on, let me know. This isn't a homework assignment. I'm just trying to teach myself how to use C.
Any help would be appreciated, since I can't figure out what I'm doing wrong with such a simple section of code....
