Here is a main()
that calls base64_encode()
:
int main(void) {
char data[] = "test";
char *encoded_data;
size_t len;
encoded_data = base64_encode(data, strlen(data), &len);
printf("%s (%zu) => %s (%zu)", data, strlen(data), encoded_data, len);
}
Explanation
char data[]
contains your string to encode. You’ll need to pass it as an argument tobase64_encode()
.char *encoded_data
is a pointer that you’ll use to store the return value ofbase64_encode()
. You will use this variable to access the decoded string, sincebase64_encode()
returns a pointer to an allocated space where the decoded string is stored.size_t len
is a variable that will be used to store the size of the decoded string. You’ll give a pointer to this variable as argument tobase64_encode()
.strlen(data)
, the second argument tobase64_encode()
, is the length ofchar data[]
.
0
solved C – Trouble calling a function