λ§€ν¬λ‘ (Macros) ¶
λ§€ν¬λ‘ λͺ | μ€λͺ |
NULL | λ ν¬μΈν° μμ κ° |
EXIT_FAILURE | μ€ν¨ν μ’ λ£ (0μ΄ μλ κ°μ κ°μ§) |
EXIT_SUCCESS | μ±κ³΅ν μ’ λ£ (0μΈ κ°μ κ°μ§) |
RAND_MAX | λλ€ ν¨μμ μν΄μ 리ν΄λλ μ΅λ κ° (μ μ΄λ 32, 767) |
MB_CUR_MAX | νμ¬ μ¬μ© μ€μΈ λ‘μΌμΌμμ λ©ν°λ°μ΄νΈ λ¬Έμμ μ΅λ κΈΈμ΄ |
λ³μ (Variables) ¶
λ³μ λͺ | μ€λͺ |
typedef size_t | sizeof ν€μλμ unsigned μ μν κ²°κ³Ό |
typedef wchar_t | νμ₯ λ¬Έμ μμ ν¬κΈ°μ μ μ νμ |
struct div_t | div() ν¨μμ μν΄ λ¦¬ν΄λλ ꡬ쑰체ν |
struct ldiv_t | idiv() ν¨μμ μν΄ λ¦¬ν΄λλ ꡬ쑰체ν |
ν¨μ (Functions) - String Functions ¶
ν¨μ λͺ | μ€λͺ |
double atof(const char *str); | λ¬Έμμ΄μ μ€μ(double precision)λ‘ λ³ν |
int atoi(const char *str); | λ¬Έμμ΄μ μ μ(integer)λ‘ λ³ν |
double strtod(const char *str, char **endptr); | λ¬Έμμ΄μ μ€μ(double precision)λ‘ λ³ν |
long int strtol(const char *str, char **endptr, int base); | λ¬Έμμ΄μ μ μ(long integer)λ‘ λ³ν |
unsigned long int strtoul(const char *str, char **endptr, int base); | λ¬Έμμ΄μ μ μ(unsigned long)λ‘ λ³ν |
ν¨μ (Functions) - Memory Functions ¶
ν¨μ λͺ | μ€λͺ |
void *calloc(size_t nitems, size_t size); | μμ²λ λ©λͺ¨λ¦¬ ν λΉ (λͺ¨λ μμλ₯Ό 0μΌλ‘ μ΄κΈ°ν νλ€) |
void free(void *ptr); | calloc(), malloc(), realloc()μ μν΄ ν λΉλ λ©λͺ¨λ¦¬ ν΄μ |
void *malloc(size_t size); | μμ²λ λ©λͺ¨λ¦¬ ν λΉ (μμλ₯Ό μ΄κΈ°ν νμ§ μλλ€) |
void *realloc(void *ptr, size_t size); | calloc(), malloc()μ μν΄ ν λΉλ λ©λͺ¨λ¦¬ ν¬κΈ°λ₯Ό μ¬μ‘°μ νλ€ |
== ν¨μ (Functions) - Environment Functions ==
ν¨μ λͺ | μ€λͺ |
void abort(void); | λΉμ μμ μΈ νλ‘κ·Έλ¨ μ’ λ£λ₯Ό λ°μμν¨λ€ |
int atexit(void (*func)(void)); | νλ‘κ·Έλ¨μ΄ μ μμ μΌλ‘ μ’ λ£λ λ μ λ¬μΈμλ‘ λκ²¨μ§ ν¨μν¬μΈν°λ₯Ό μ΄μ©ν΄μ νΉμ ν¨μ μ€ν |
void exit(int status); | μ μμ μΈ νλ‘κ·Έλ¨ μ’ λ£λ₯Ό λ°μμν¨λ€ |
char *getenv(const char *name); | νκ²½ λ³μλ₯Ό μ»λλ€ |
int system(const char *string); | μ λ¬μΈμλ‘ λ°μ λͺ λ Ή μ€ν |
ν¨μ (Functions) - Searching and Sorting Functions ¶
ν¨μ λͺ | μ€λͺ |
void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *)); | μ΄μ§κ²μ μν |
void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*)); | ν΅ μνΈ μν |
ν¨μ (Functions) - Math Functions ¶
ν¨μ λͺ | μ€λͺ |
int abs(int x); | μ μν μ λκ° λ¦¬ν΄ |
div_t div(int numer, int denom); | μ λ¬μΈμμ numerλ₯Ό denomμΌλ‘ λλ κ°κ³Ό λλ¨Έμ§λ₯Ό ꡬ쑰체νμμΌλ‘ λ¦¬ν΄ |
long int labs(long int x); | longν μ μμ μ λκ°μ λ¦¬ν΄ |
ldiv_t ldiv(long int numer, long int denom); | div()μ λμΌνκ³ λ³μ νμ λ§ long int |
int rand(void); | 0λΆν° RAND_MAXκΉμ§μ λ²μμ¬μ΄μ λμ λ¦¬ν΄ |
void srand(unsigned int seed); | rand()μ μν΄ μ¬μ©λλ λμ μμ±κΈ°μ μΈμ κ³΅κΈ |
ν¨μ (Functions) - Multibyte Functions ¶
ν¨μ λͺ | μ€λͺ |
int mblen(const char *str, size_t n); | λ€μ€ λ°μ΄νΈ λ¬Έμμ κΈΈμ΄ λ¦¬ν΄ |
size_t mbstowcs(schar_t *pwcs, const char *str, size_t n); | λ€μ€ λ°μ΄νΈ λ¬Έμ μ€νΈλ§μ wide λ¬Έμ μ€νΈλ§μΌλ‘ λ³ν |
int mbtowc(whcar_t *pwc, const char *str, size_t n); | λ€μ€ λ°μ΄νΈ λ¬Έμλ₯Ό wide λ¬Έμλ‘ λ³ν |
size_t wcstombs(char *str, const wchar_t *pwcs, size_t n); | wide λ¬Έμ μ€νΈλ§μ λ€μ€ λ°μ΄νΈ μ€νΈλ§μΌλ‘ λ³ν |
int wctomb(char *str, wchar_t wchar); | wide λ¬Έμλ₯Ό λ€μ€ λ°μ΄νΈ λ¬Έμλ‘ λ³ν |
stdlib.h μ ν¨μ μμ ¶
strtod(), strtol(), strtoul() μμ μ½λ ¶
~cpp #include <stdlib.h> #include <stdio.h> void main( void ) { char *string, *stopstring; double x; long l; int base; unsigned long ul; string = "3.1415926This stopped it"; x = strtod( string, &stopstring ); printf( "string = %s\n", string ); printf(" strtod = %f\n", x ); printf(" Stopped scan at: %s\n\n", stopstring ); string = "-10110134932This stopped it"; l = strtol( string, &stopstring, 10 ); printf( "string = %s", string ); printf(" strtol = %ld", l ); printf(" Stopped scan at: %s", stopstring ); string = "10110134932"; printf( "string = %s\n", string ); /* Convert string using base 2, 4, and 8: */ for( base = 2; base <= 8; base *= 2 ) { /* Convert the string: */ ul = strtoul( string, &stopstring, base ); printf( " strtol = %ld (base %d)\n", ul, base ); printf( " Stopped scan at: %s\n", stopstring ); } }
strtod(), strtol(), strtoul() μ€ν κ²°κ³Ό ¶
string = 3.1415926This stopped it
string = -10110134932This stopped it strtol = -2147483647 Stopped scan at: This stopped itstring = 10110134932
strtod = 3.141593
Stopped scan at: This stopped it
Stopped scan at: This stopped it
strtol = 45 (base 2)
Stopped scan at: 34932
strtol = 4423 (base 4)
Stopped scan at: 4932
strtol = 2134108 (base 8)
Stopped scan at: 932
Stopped scan at: 34932
strtol = 4423 (base 4)
Stopped scan at: 4932
strtol = 2134108 (base 8)
Stopped scan at: 932
malloc() μμ μ½λ ¶
~cpp #include <stdlib.h> /* For _MAX_PATH definition */ #include <stdio.h> #include <malloc.h> int main( void ) { char *string; /* Allocate space for a path name */ string = malloc( _MAX_PATH ); // In a C++ file, explicitly cast malloc's return. For example, // string = (char *)malloc( _MAX_PATH ); if( string == NULL ) printf( "Insufficient memory available\n" ); else { printf( "Memory space allocated for path name\n" ); free( string ); printf( "Memory freed\n" ); } }
malloc() μ€ν κ²°κ³Ό ¶
Memory space allocated for path name
Memory freed
Memory freed
qsort(), bsearch() μμ μ½λ ¶
~cpp #include<stdlib.h> #include<stdio.h> #include<string.h> int main(void) { int i; char string_array[10][50]={"John", "Jane", "Mary", "Rogery", "Dave", "Paul", "Beavis", "Astro", "George", "Elroy"}; /* μ λ ¬ μ */ for (i = 0; i < 10; i++) printf("%s, ", string_array[i]); printf("\n"); /* Sort the list */ qsort(string_array, 10, 50, strcmp); /* μ λ ¬ ν */ for (i = 0; i < 10; i++) printf("%s, ", string_array[i]); printf("\n"); /* Search for the item "Elroy" and print it */ printf("%s\n",bsearch("Elroy", string_array, 10, 50, strcmp)); return 0; }
qsort(), bsearch() μ€ν κ²°κ³Ό ¶
John, Jane, Mary, Rogery, Dave, Paul, Beavis, Astro, George, Elroy,
Astro, Beavis, Dave, Elroy, George, Jane, John, Mary, Paul, Rogery,
Elroy
----
OurMajorLangIsCAndCPlusPlus
Astro, Beavis, Dave, Elroy, George, Jane, John, Mary, Paul, Rogery,
Elroy
OurMajorLangIsCAndCPlusPlus