Midterm Reference Sheet

This is the function list that will be distributed with the midterm exam. You will not use every function listed and you may use standard library functions not listed (unless otherwise restricted in the exam requirements).

Common C library functions

C-strings

size_t strlen(const char *str);
int    strcmp(const char *s, const char *t);
int    strncmp(const char *s, const char *t, size_t n);
char  *strchr(const char *s, int ch);
char  *strstr(const char *haystack, const char *needle);
char  *strcpy(char *dst, const char *src);
char  *strncpy(char *dst, const char *src, size_t n);
char  *strcat(char *dst, const char *src);
char  *strncat(char *dst, const char *src, size_t n);
size_t strspn(const char *s, const char *accept);
size_t strcspn(const char *s, const char *reject);
char  *strdup(const char *s);

int atoi(const char *s);
long strtol(const char *s, char **endptr, int base);

Memory

void *malloc(size_t sz);
void *calloc(size_t nmemb, size_t sz);
void *realloc(void *ptr, size_t sz);
void  free(void *ptr);

void *memcpy(void *dst, const void *src, size_t n);
void *memmove(void *dst, const void *src, size_t n);
void *memset(void *base, int byte, size_t n);

Search and sort

void  qsort(void *base, size_t nelems, size_t width,
             int (*compar)(const void *, const void *));
void *bsearch(const void *key, const void *base, size_t nelems, size_t width,
               int (*compar)(const void *, const void *));
void *lfind(const void *key, const void *base, size_t *p_nelems, size_t width, 
             int(*compar)(const void *, const void *));
void *lsearch(const void *key, void *base, size_t *p_nelems, size_t width,
               int(*compar)(const void *, const void *));

I/O

char *fgets(char buf[], int buflen, FILE *fp);