求助,急啊
把一个2进制浮点数据101011.01011110011101 转成十进制后,寸到文件中, 对生成的double型数据如何存到文件中, char binaryNUM[]=101011.01011110011101 和 int a[] =decimalNum ;有错误,求高手帮改改#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
int main(void)
{
char binaryNUM[]=101011.01011110011101 ;
char *P=binaryNUM;
double decimalNum = 0;
int n = 0, dotsNum = 0, i = 0, j = 0;
if (dotsNum) /******
j = n -1 - i; ******
else 数据处理部分
i = n; (将二进制浮点数进行处理生成十进制的数据)
for ( ; i > 0; p++, i--) ******
if (*p == '1') ******
decimalNum += pow(2, i -1); ******
for (p++, i = 1; i <= j; p++, i++) ******
if (*p == '1') ******
decimalNum += pow(2, -i); ******/
FILE *fp;
int num;
int folder;
int a[] =decimalNum ;
fp = fopen("/tmp/sd/linux.txt","w+"); /*打开SD卡上的TXT文件.*/
if(fp == NULL)
{
printf("\nCan't open linux.txt!\n");
exit(-1);
}
num = fwrite(a, sizeof(a), 1, fp); /*将生成的十进制数据写TXT文件中*/
printf("%d byte data has written to linux.txt\n", num*sizeof(a));
folder = mkdir("/tmp/sd/linux", 1);
if(folder == -1)
{
printf("\n Cann't create folder linux!\nIt has existed or the path is error!\n");
exit(-1);
}
printf("Folder linux created success!\n");
close(fp); /*关闭TXT文件*/
return 0; /*返回*/
}
[[it] 本帖最后由 lansha001 于 2008-4-29 13:52 编辑 [/it]]