I l @ ve RuBoard |
The proper keyword is struct , not structure . The template requires either a tag before the opening brace or a variable name after the closing brace . Also, there should be a semicolon after * togs and at the end of the template.
Here is the output:
6 1 22 Spiffo Road S p
struct month { char name[10]; char abbrev[4]; int days; int monumb; };
struct month months[12] = { {"January", "jan", 31, 1}, {"February", "feb", 28, 2}, {"March", "mar", 31, 3}, {"April", "apr", 30, 4}, {"May", "may", 31, 5}, {"June", "jun", 30, 6}, {"July", "jul", 31, 7}, {"August", "aug", 31, 8}, {"September", "sep", 30, 9}, {"October", "oct", 31, 10}, {"November", "nov", 30, 11}, {"December", "dec", 31, 12} };
extern struct month months[]; int days(int month) { int index, total; if (month < 1 month > 12) return(-1); /* error signal */ else { for (index = 0, total = 0; index < month; index ++) total += months[index].days; return( total); } }
Note that index is one less than the month number because arrays start with subscript 0. Therefore, use index < month instead of index <= month .
Include string.h to provide strcpy () :
LENS bigEye[10]; bigEye[2].foclen = 500; bigEye[2] fstop = 2.0; strcpy(bigEye[2].brand, "Remarkatar"); typedef struct lens { /* lens descriptor */ float foclen; /* focal length,mm */ float fstop; /* aperture */ char brand[30]; /* brand name */ } LENS;
6 Arcturan cturan
Use the structure name and use the pointer:
deb.title.last pb->title.last
Here is one version:
#include <stdio.h> #include "starfolk.h" /* make struct defs available */ void prbem (const struct bem * pbem ) { printf("%s %s is a %d-limbed %s.\n", pbem->title.first, pbem->title.last, pbem->limbs, pbem->type); }
willie.born
pt->born
scanf("%d", &willie.born);
scanf("%d", &pt->born);
willie.name.fname[2]
strlen(willie.name.fname) + strlen(willie.name.lname)
Here is one possibility:
struct car { char name[20]; float hp; float epampg; float wbase; int year; };
The function could be set up like this:
struct gas { float distance; float gals; float mpg; }; struct gas mpgs(struct gas trip) { if (trip.gals > 0) trip.mpg = trip.distance / trip.gals ; else trip.mpg = -1.0; return trip; }
Note that this function cannot directly alter values in the calling program, so you must use the return value to convey the information:
struct gas idaho; idaho = mpgs(idaho);
char * (*pfun)(char *, char);
double sum(double, double); double diff(double, double); double times(double, double); double divide(double, double); double (*pf1[4])(double, double) = {sum, diff, times, divide};
Or, more simply, replace the last line of code with these lines:
typedef double (*ptype)(double, double); ptype pf[4] = {sum, diff, times, divide};
I l @ ve RuBoard |