#include <filename.h> |
#include "filename.h" |
extern int getline(char [], int); |
#include "myio.h" |
#define name text |
#undef name |
char line[100]; ... getline(line, 100); |
#define MAXLINE 100 char line[MAXLINE]; ... getline(line, MAXLINE); |
#define MAXLINE 100; /* WRONG */ |
char line[MAXLINE]; |
char line[100;]; /* WRONG */ |
#define A 2 #define B 3 #define C A + B int x = C * 2; |
int x = A + B * 2; |
int x = 2 + 3 * 2; |
#define C (A + B) |
#ifdef name program text #else more program text #endif |
#if 0 program text #endif |
cl.exe -Dname |
#ifdef unix unlink(filename); #else remove(filename); #endif |
#define unix |
#ifdef DEBUG printf("x is %d\n", x); #endif |
#include |
*p = 0; |
char *somestring, *copy; ... copy = (char *) malloc(strlen(somestring) + 1); /* +1 for \0 */ /* check malloc's return value */ strcpy(copy, somestring); |
int *ip = (int *) malloc(100 * sizeof(int)); |
int *ip = (int *) malloc(100 * sizeof(int)); |
int *ip = (int *) malloc(100 * sizeof(int)); if(ip == NULL) { printf("out of memory\n"); exit or return } |
free(p); |
free(p); |
free(p); p = NULL; |
ip = realloc(ip, 200 * sizeof(int)); |
#define MAXLINE 100 char line[MAXLINE]; int *ip; int nalloc, nitems; nalloc = 100; ip = (int *) malloc(nalloc * sizeof(int)); /* initial allocation */ if (ip == NULL) { printf("out of memory\n"); exit(1); } nitems = 0; while (getline(line, MAXLINE) != EOF) { if (nitems >= nalloc) { /* increase allocation */ int *newp; nalloc += 100; newp = realloc(ip, nalloc * sizeof(int)); if (newp == NULL) { printf("out of memory\n"); exit(1); } ip = newp; } ip[nitems++] = atoi(line); } |