帮忙看个程序
该程序是用键盘输入一个二进制浮点数,然后转化成十进制的数据后,将数据存到一个文件中,本程序共54行,但是错误报告中说,55行有错,parse error at end of input#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[100];
char *p = binaryNum;
double decimalNum = 0;
int n = 0, dotsNum = 0, i = 0, j = 0;
printf("Please type in a binary number:\n");
scanf("%s", &binaryNum);
for ( ; *p != '\0'; p++, n++) {
if (! (*p == '0' || *p == '1' || *p == '.')) {
printf("bad input!\n");
return 1;
}
if (*p == '.') {
dotsNum++;
if (dotsNum == 1)
i = n;
else {
printf("bad binary number!\n");
return 1;
if (dotsNum)
j = n -1 - i;
else
i = n;
p = binaryNum;
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;
fp = fopen("/tmp/sd/linux.txt","w+");
if(fp == NULL)
{
printf("\nCan't open linux.txt!\n");
exit(-1);
}
num = fprintf(fp, "%lf\n",decimalNum);
printf("%d byte data has written to linux.txt\n", num*sizeof(decimalNum));
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");
fclose(fp);
return 0;
}