--------------------------------
typedef enum {now=10, next, last} grade;
typedef union {int age1; float age2;} age;
main()
{
struct {char name[20]; int age;} info;
strcpy(info.name, "name goes here");
grade now
info.age=15;
UNION age=info.age;
//parse error before 'union'
printf("This program is by %s, age %d. He is currently is grade %d." INFO.name, age.age2, grade);
} // parse error before 'info'
--------------------------------
There are probably other errors, but Dev isn't pointing them out. Any help would be appreciated. : )
Having parse errors in a C program, help please.?
1) You need a semicolon at the end of the line:
grade now
2) On the line:
UNION age=info.age;
I'm really not sure what you're trying to do here. Are you trying to create a variable, of type age, and set it's age1 variable to the value of info.age? Instead of that one line, you could try:
age myAge;
myAge.age1 = info.age;
And then in the line where you use printf(), instead of age.age2 you could type:
myAge.age1
3) In the line that begins:
printf("This
a) You refer to INFO.name, but there is no variable called INFO, only info. The C programming language is case sensitive.
b) You're missing a comma after:
is grade%d."
c) As the last parameter for printf(), you typed "grade", but grade is a type, now is the actual variable.
I hope this was helpful!
Reply:Missing a comma, I got the following to compile:
printf("This program is by %s, age %d. He is currently is grade %d.", false, false, false);
Reply:// The program below will compile and run
// and produce output.
// You have to think carefully about types,
// variables and variable assignments
// Plus a few minor typos.
// way to go!
#include %26lt;string.h%26gt;
typedef enum {now=10, next, last} grade;
typedef union {int age1; float age2;} age;
void main()
{
struct {
char name[20];
int age;
} info;
strcpy(info.name, "name goes here");
// grade is a type, myGrade a var of type grade.
// assign a value
grade myGrade = now; // semi missing
info.age=15;
// age is of type union { }
age myage; // union
myage.age1 = info.age; // assign
printf("This program is by %s, age %d. He is currently is grade %d.\n",
info.name, myage.age1, myGrade );
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment