§ — — Computer Programming 1
Include <string.h> to use these functions.
strcpy(destination, source) // copy source into destination
strncpy(target, source, n) // copy at most n characters
strcat(str1, str2) // append str2 to end of str1
strncat(str1, str2, n) // append at most n characters
strcmp(str1, str2) // returns: <0 if str1<str2, 0 if equal, >0 if str1>str2
stricmp(str1, str2) // compare, ignoring case
strncmp(str1, str2, n) // compare at most n characters
strlwr(str) // convert to lowercase
strupr(str) // convert to uppercase
strlen(str) // return length (not counting '\0')
strrev(str) // reverse the string in place
strdup(str) // return a duplicate
strchr(str, c) // pointer to first occurrence of c
strset(str, ch) // set all characters to ch
strnset(str, ch, n) // set first n characters to ch
<math.h>| Function | Syntax | Description |
|---|---|---|
abs() | int abs(int num) | Absolute value of integer |
fabs() | double fabs(double num) | Absolute value of float |
ceil() | double ceil(double num) | Smallest integer ≥ num (round up) |
floor() | double floor(double num) | Largest integer ≤ num (round down) |
fmod() | double fmod(double x, double y) | Remainder of x/y (float modulus) |
pow() | double pow(double base, double exp) | base raised to exp |
sqrt() | double sqrt(double num) | Square root (num must be ≥ 0) |
<ctype.h>| Function | Tests/Does |
|---|---|
isalnum(ch) | True if letter or digit |
isalpha(ch) | True if letter |
isdigit(ch) | True if digit (0–9) |
islower(ch) | True if lowercase letter |
isupper(ch) | True if uppercase letter |
ispunct(ch) | True if punctuation (not space) |
isspace(ch) | True if whitespace |
tolower(ch) | Returns lowercase version |
toupper(ch) | Returns uppercase version |
<stdlib.h>| Function | Description |
|---|---|
atof(str) | Convert string to double |
atoi(str) | Convert string to int |
atol(str) | Convert string to long int |
itoa(num, str, radix) | Convert int to string in given base |
ProReviewer — locked
Drills, code labs, and full solutions.
ProReviewer — locked
Drills, code labs, and full solutions.
ProReviewer — locked
Drills, code labs, and full solutions.
Experiment with other math.h functions like ceil(), floor(), or log(). Try changing the string too.
Done with this module? Track it — your progress shows on the subject list.
Up next
Exam Prep: Prelims & Finals→←Previous: Lesson 6: Functions