Converting char array to int16 type
Hello guys,
i know this is a very old question with millions of solutions and believe me i have tried some of those solutions but the result is not coming up.
I am trying to convert a char buffer[1024] with raw data to int 16 buffer2[1024] which is supposed to have hex data (0x01, 0x02 kind of format).
code i am trying with is:
Code:
char temp_buffer[1024];
block_size = sizeof(temp_buffer);
num_blocks = sizeof(char);
Status = mount(0, &myfsObject);
if(Status != DAVEApp_SUCCESS)
{
while(1);
}
ptr = fopen("test1.raw", "r+");
fseek(ptr, 0, SEEK_SET);
result = fread(&temp_buffer, num_blocks, block_size, ptr);
for (i=0;i<1024;i++)
{
UTXBuf1[i] = temp_buffer[i] - '0';
}
ptr = fopen("test2.txt", "w+");
fseek(ptr, 0, SEEK_SET);
block_size = sizeof(UTXBuf1);
//num_blocks = sizeof(char);
fwrite(&UTXBuf1, 1, block_size, ptr);
status1 = fclose(ptr);
As you can figure out that i am verifying the data of resultant buffer by creating a new file and writing data to it.
The result which i got is:
Code:
H ья H ья H ья H ья H ья H ья H ья H ья
If something is missing then please let me know.
Any help would be appreciated.
Thanks