| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 461 人关注过本帖
标题:帮忙看个程序
只看楼主 加入收藏
lansha001
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-4-12
收藏
 问题点数:0 回复次数:1 
帮忙看个程序
该程序是用键盘输入一个二进制浮点数,然后转化成十进制的数据后,将数据存到一个文件中,本程序共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;
}
2008-05-03 08:25
qq490456661
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-5-2
收藏
得分:0 
55行...要我去数么......
2008-05-03 08:28
快速回复:帮忙看个程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037424 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved