// Ivan Novick 2007 // test apr string functions // gcc -I/usr/include/apr-1.0 `apr-config --cppflags --cflags` -lapr-1 apr_string.c -o apr_string -std=c99 #include #include #include #include int main(int argc, char** argv) { apr_pool_t* my_pool; // init the apr library if (apr_initialize()) { fprintf(stderr, "could not initialize apr \n"); exit(1); } // create a memory pool to allocate memory from if (apr_pool_create(&my_pool, NULL) ) { fprintf(stderr, "could not create memory pool\n"); exit(1); } // convert int to string and allocate memory for the strings char* s1 = apr_itoa(my_pool, 50); fprintf(stdout, "%s\n", s1); // convert int to string and allocate memory for the strings char* s2 = apr_itoa(my_pool, 75); fprintf(stdout, "%s\n", s2); // convert int to string and allocate memory for the strings char* s3 = apr_itoa(my_pool, 100); fprintf(stdout, "%s\n", s3); // concatenate 4 strings and put result into new memory pointed to by s4 // the final string must be NULL char* s4 = apr_pstrcat(my_pool, s1, s2, s3, NULL); fprintf(stdout, "%s\n", s4); // sprintf style function but the memory comes from pool char* text = apr_psprintf(my_pool, "Hello World %.2f %d", 10.0/3, 99); fprintf(stdout, "%s\n", text); // free all the memory from the pool apr_pool_destroy(my_pool); // to make library cleanup resources apr_terminate(); return 0; }