Just call it with the data, the length and the buffer where you want your output;
char* data = "my data to hash";
int datalen = strlen(data); // or if binary data, the size of your input
unsigned char buffer[32]; // The buffer to receive the result
sha2(data,datalen,buffer);
Note that the data received in the buffer is binary data (32*8=256 bits if it's SHA-256), so you'll want to hex/base64/etc. encode it before displaying the result to a screen.
EDIT: Extremely simple and hackish hex encoding entirely without clean code points :)
char* hexencode(void* data, int len)
{
char* outdata = malloc(len*2+1);
char* tmp = outdata;
unsigned char* indata = (char*)data;
while(len--)
{
*tmp++ = "0123456789abcdef"[(*indata)>>4];
*tmp++ = "0123456789abcdef"[(*indata++)&0xf];
}
*tmp = 0;
return outdata;
}
memset?memsetwould be not to leave SHA-2 context on the stack that could be used to reverse engineer the original string. The hash is resilient to reversing, the context state may not be. Of course in this case there's the whole issue of the original string not being overwritten too... :)