CS107 Exam C Reference Sheet
CS107 Exam C Reference Sheet
C Strings
size_t strlen(const char *str);
returns the length of str
Memory
void *malloc(size_t sz);
allocates size bytes and returns a pointer to the allocated memory.
The memory is not initialized.
void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
The bsearch() function searches an array of nmemb objects, the initial
member of which is pointed to by base, for a member that matches the object
pointed to by key. The size of each member of the array is specified
by size. The contents of the array should be in ascending sorted order
according to the comparison function referenced by compar.
I/O
char *fgets(char buf[], int buflen, FILE *fp);
fgets() reads in at most buflen - 1 characters from fp and
stores them into the buffer addressed by buf. Reading stops after an
EOF or a newline. If a newline is read, it is stored into the buffer.
A terminating null byte ('\0') is stored after the last character in
the buffer. fgets() returns buf on success, and NULL on error or when
end of file occurs while no characters have been read.