1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
// { "hello", "world" }
bool create_string(char** a_result) {
// note: we want sizeof(char), so dereference twice
char* output = malloc(sizeof(*output) * 4);
*a_result = output;
output[0] = 'a';
output[1] = 'b';
output[2] = 'c';
output[3] = '\0';
return true;
}
int main(int argc, char* argv[]) {
char* result; // unititalized
bool is_success = create_string(&result);
printf("success: %d, result: %s\n", is_success, result);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2022 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.