Greetings!
I am learning C and I came up with this program to test my knowledge.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char s[128];
void *p;
sprintf(s, "%p", malloc(0x10));
puts(s);
sscanf(s, "%p", &p);
printf("%p\n", p);
free(p);
return 0;
}
Is it OK? Even if malloc returns NULL?
One thing I am not sure of is what the size of s should be. Is 128
enough? Or too much? How should I know how big to make it?
Thanks in advance -- Andy!
I am learning C and I came up with this program to test my knowledge.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char s[128];
void *p;
sprintf(s, "%p", malloc(0x10));
puts(s);
sscanf(s, "%p", &p);
printf("%p\n", p);
free(p);
return 0;
}
Is it OK? Even if malloc returns NULL?
One thing I am not sure of is what the size of s should be. Is 128
enough? Or too much? How should I know how big to make it?
Thanks in advance -- Andy!
Comment