I l @ ve RuBoard |
dist = 5280 * miles; is valid.
plort = 4 * 4 + 4; is valid. But if the user really wanted 4 * (4 + 4) , he or she should have used #define POD (FEET + FEET) .
nex = = 6;; is valid, but not meaningful. Apparently the user forgot that he or she was writing for the preprocessor, not writing in C.
y = y + 5; is valid. berg = berg + 5 * lob; is valid, but this is probably not the desired result. est = berg + 5/ y + 5; is valid, but this is probably not the desired result. nilp = lob *-berg + 5; is valid, but this is probably not the desired result.
#define NEW(X) ((X) + 5)
#define MIN(X,Y) ( (X) < (Y) ? (X) : (Y) )
#define EVEN_GT(X,Y) ( (X) > (Y) && (X) % 2 == 0 ? 1 : 0 )
#define PR(X,Y) printf(#X " is %d and " #Y " is %d\n", X,Y)
Because X and Y are never exposed to any other operations (such as multiplication) in this macro, you don't have to cocoon everything in parentheses.
#define QUARTERCENTURY 25
#define SPACE ' '
#define PS() putchar (' ') or #define PS() putchar(SPACE)
#define BIG(X) ((X) + 3)
#define SUMSQ(X,Y) ((X)*(X) + (Y)*(Y))
Try this:
#define P(X) printf("name: "#X"; value: %d; address: %p\n", X, &X)
Or, if your implementation doesn't recognize the %p specification for the address, try %u or %lu .
Use the conditional compilation directives. One way is to use # ifndef :
#define _SKIP_ /* remove when you don't want to skip code */ #ifndef _SKIP_ /* code to be skipped */ #endif
enum days {sun, mon, tue, wed, thu, fri, sat}; /* 0 - 6 enum days {sun = 1, mon, tue, wed, thu, fri, sat}; / 1 - 7 */
enum days visit;
The argv argument should be declared as type char *argv[] . Command-line arguments are stored as strings, so the program should first convert the string in argv[1] to a type double value, for example, by using atof() from the stdlib.h library. The math.h header file should be included for the sqrt() function. The program should check for negative values before taking a square root.
The function call should look like this:
qsort( (void *)scores, (size_t) 1000, sizeof (double), comp);
Here's a suitable comparison function:
int comp(const void * p1, const void * p2) { /* need to use pointers to int to access values */ const int * a1 = p1; /* a1 is proper pointer type */ const int * a2 = p2; if (*a1 > *a2) return -1; else if (*a1 == *a2) return 0; else return 1; }
The program should include the stdlib.h file , if available, or else declare malloc() or calloc () .
struct wine * ptrwine; ptrwine = (struct wine *) calloc(100, sizeof (struct wine));
or
ptrwine = (struct wine *) malloc(100 * sizeof (struct wine));
I l @ ve RuBoard |