| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1319 人关注过本帖
标题:c语言程序,运行出错,但是我不知道怎么改,我只会点皮毛,高手指点啊,编译 ...
取消只看楼主 加入收藏
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:12 
c语言程序,运行出错,但是我不知道怎么改,我只会点皮毛,高手指点啊,编译器VC++2010
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#ifndef M_PI
#ifdef _PI
#define M_PI _PI
#else
#define M_PI        3.14159265358979323846
#endif
#endif
#define DIM 3
#define XX 0
#define YY 1
#define ZZ 2
double H , D , wall_radius , inner_radius ,x_min ,x_max , one_fill_H , two_fill_H;
int one_Num , two_Num;
int nx=0,ny=0, nz=0;
double lx=0.0, ly=0.0, lz=0.0;
double circle_radius = 0.0;
double x=0.0,y=0.0,z=0.0;
char temp[100];
int count = 0;
int i,j,k;
int main()
{
    FILE *pout = fopen("para.ini", "r");
    FILE *fout = fopen("x.xyz", "w");
    FILE *fout1 = fopen("data.txt", "w");
    if(!pout)
    {
        printf("Can not open file to read!\n");
        exit(1);
    }
    if(!fout)
    {
        printf("Can not open file to write!\n");
        exit(1);
    }
    if(!fout1)
    {
        printf("Can not open file1 to write!\n");
        exit(1);
    }
    fscanf(pout, "%s%lf", temp, &H);
    fscanf(pout, "%s%lf", temp, &D);
    fscanf(pout, "%s%lf", temp, &x_min);
    fscanf(pout, "%s%lf", temp, &one_fill_H);
    fscanf(pout, "%s%lf", temp, &two_fill_H);
    fscanf(pout, "%s%d", temp, &one_Num);
    fscanf(pout, "%s%d", temp, &two_Num);
    fscanf(pout, "%s%lf", temp, &wall_radius);
    fscanf(pout, "%s%lf", temp, &inner_radius);
    fclose(pout);
    x_max = H + 2.0*wall_radius + x_min;
    double box[DIM]={H+2.0*wall_radius+2.0*x_min, D+4.0*wall_radius, D+4.0*wall_radius};  //filling district : H,W,D
    printf("box[x] = %lf\nbox[y] = %lf\nbox[z] = %lf\n",box[XX],box[YY],box[ZZ]);


    ////-----------------------------------------------------------------

    double fill_circle_radius = (D-4.0*inner_radius) / 2.0;
    int one_fill_nx = (int)(one_fill_H / (2.0*inner_radius));
    double fill_x_step = 2.0*inner_radius;
    int fill_n_left_right = int(fill_circle_radius / inner_radius);
    double fill_step_left = inner_radius;
  double angle = 0.0;
    int n = 0;
  double tmp_x =0.0;
    for(k=0;k<=one_fill_nx;k++)
    {
        x = x_min+4.0*inner_radius + inner_radius + k*fill_x_step;
        if (x>tmp_x) tmp_x = x;
      for(i=0;i
搜索更多相关主题的帖子: c语言程序 include double 编译器 
2013-01-08 10:39
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 2楼 麦香
出的错误虽然很多,但是好像是其中的box[]等的定义有问题,其他的错误也是类似。比如:
"box":未声明的标示符
缺少“;”(在类型的前面)
这个代码我运行看了下,觉得错误不是大问题,可是我不懂C语法,定义之类的错误我也不知从哪入手去改,所以想请大侠运行下,看看这是怎么回事,代码虽然很长,但是只改定义之类的,还是希望有大侠出手相助……
2013-01-08 10:53
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 2楼 麦香
没贴完整么,好吧,我再去贴下,第一次发帖,不太会……
2013-01-08 10:59
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 2楼 麦香
程序代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#ifndef M_PI
#ifdef _PI
#define M_PI _PI
#else
#define M_PI        3.14159265358979323846
#endif
#endif
#define DIM 3
#define XX 0
#define YY 1
#define ZZ 2
double H , D , wall_radius , inner_radius ,x_min ,x_max , one_fill_H , two_fill_H;
int one_Num , two_Num;
int nx=0,ny=0, nz=0;
double lx=0.0, ly=0.0, lz=0.0;
double circle_radius = 0.0;
double x=0.0,y=0.0,z=0.0;
char temp[100];
int count = 0;
int i,j,k;
int main()
{
    FILE *pout = fopen("para.ini", "r");
    FILE *fout = fopen("x.xyz", "w");
    FILE *fout1 = fopen("data.txt", "w");
    if(!pout)
    {
        printf("Can not open file to read!\n");
        exit(1);
    }
    if(!fout)
    {
        printf("Can not open file to write!\n");
        exit(1);
    }
    if(!fout1)
    {
        printf("Can not open file1 to write!\n");
        exit(1);
    }
    fscanf(pout, "%s%lf", temp, &H);
    fscanf(pout, "%s%lf", temp, &D);
    fscanf(pout, "%s%lf", temp, &x_min);
    fscanf(pout, "%s%lf", temp, &one_fill_H);
    fscanf(pout, "%s%lf", temp, &two_fill_H);
    fscanf(pout, "%s%d", temp, &one_Num);
    fscanf(pout, "%s%d", temp, &two_Num);
    fscanf(pout, "%s%lf", temp, &wall_radius);
    fscanf(pout, "%s%lf", temp, &inner_radius);
    fclose(pout);
    x_max = H + 2.0*wall_radius + x_min;
    double box[DIM]={H+2.0*wall_radius+2.0*x_min, D+4.0*wall_radius, D+4.0*wall_radius};  //filling district : H,W,D
    printf("box[x] = %lf\nbox[y] = %lf\nbox[z] = %lf\n",box[XX],box[YY],box[ZZ]);
    //----------------------------------------------------------------------------------
    ////---------------------------------------------------------------------------
    double fill_circle_radius = (D-4.0*inner_radius) / 2.0;
    int one_fill_nx = (int)(one_fill_H / (2.0*inner_radius));
    double fill_x_step = 2.0*inner_radius;
    int fill_n_left_right = int(fill_circle_radius / inner_radius);
    double fill_step_left = inner_radius;
  double angle = 0.0;
    int n = 0;
  double tmp_x =0.0;
    for(k=0;k<=one_fill_nx;k++)
    {
        x = x_min+4.0*inner_radius + inner_radius + k*fill_x_step;
        if (x>tmp_x) tmp_x = x;
      for(i=0;i<fill_n_left_right;i++)
     {
            double tmp_circle_radius = fill_circle_radius - (double)(i*fill_step_left);
            double fill_sin_theta_2 = sin(inner_radius/tmp_circle_radius);
          double fill_theta = 2.0 * asin(fill_sin_theta_2);
            int fill_n_circle = int(2.0*M_PI / fill_theta) ;
       

            for(j=0;j<fill_n_circle;j++)
            {
                angle = fill_theta*j;
                y = tmp_circle_radius*cos(angle);
                z = sin(angle)*tmp_circle_radius;
                n ++;
                if(n <= one_Num)
                {
                    count ++;
                    fprintf(fout1, "%8d%12.4f%12.4f%12.4f%8.4f%8.4f%8.4f\n", count, x, y, z, 0.0, 0.0, 0.0);
                    fprintf(fout, "%s%12.4f%12.4f%12.4f\n", "one", x, y, z);
                }
            }
        }
    }
    int one_fill_Num = count;
    printf ("one_fill_Num = %d\n",one_fill_Num);
    printf("n = %d\n",n);
    if (n> one_Num) printf("one_fill_H is too large\n");
        //-------------------------------------------------------------------
    int m = 0;
  int two_fill_nx = (int)(two_fill_H / (2.0*inner_radius));
    for(k=0;k<=two_fill_nx;k++)
    {
        x = tmp_x + 2.0*inner_radius + k*fill_x_step;
      for(i=0;i<fill_n_left_right;i++)
     {
            double tmp_circle_radius = fill_circle_radius - (double)(i*fill_step_left);
            double fill_sin_theta_2 = sin(inner_radius/tmp_circle_radius);
          double fill_theta = 2.0 * asin(fill_sin_theta_2);
            int fill_n_circle = int(2.0*M_PI / fill_theta) ;
       

            for(j=0;j<fill_n_circle;j++)
            {
                angle = fill_theta*j;
                y = tmp_circle_radius*cos(angle);
                z = sin(angle)*tmp_circle_radius;
                m ++;
                if(m <= two_Num)
                {
                    count ++;
                    fprintf(fout1, "%8d%12.4f%12.4f%12.4f%8.4f%8.4f%8.4f\n", count, x, y, z, 0.0, 0.0, 0.0);
                    fprintf(fout, "%s%12.4f%12.4f%12.4f\n", "two", x, y, z);
                }
            }
        }
    }
    int two_fill_Num = count - one_fill_Num;
    int fill_Num = count;
    printf ("two_fill_Num = %d\n",two_fill_Num);
    printf("m = %d\n",m);
    if (m> two_Num) printf("two_fill_H is too large\n");
    printf ("fill_Num = %d\n",fill_Num);
///-------------------------------------------------------------------------------------
    int nx = (int)(box[XX] / (2.0*wall_radius)) + 1;
    double x_step = box[XX] / nx;
    // compute n_circle
    ly = box[YY] - 2.0*wall_radius;
    circle_radius = ly / 2.0;
    double sin_theta_2 = sin(wall_radius/circle_radius);
    double theta = 2.0 * asin(sin_theta_2);
    int n_circle = int(2.0*M_PI / theta) + 1;
    theta = 2.0*M_PI / (double)n_circle;
    // loop along the box[XX]
    for(j=0;j<nx;j++)
    {
        x = x_step/2.0 + j*x_step;
        // loop the circle
        for(i=0;i<n_circle;i++)
        {
            count ++;
            double angle = theta*i;
            y = sin(angle)*circle_radius;
            z = cos(angle)*circle_radius;
            fprintf(fout1, "%8d%12.4f%12.4f%12.4f%8.4f%8.4f%8.4f\n", count, x, y, z, 0.0, 0.0, 0.0);
            fprintf(fout, "%s%12.4f%12.4f%12.4f\n", "wall", x, y, z);
        }
    }
    //----------------------------------------
    int n_left_right = int(circle_radius / wall_radius) + 1;
    double step_left = circle_radius / (double)n_left_right;
    // ---------------------------------
    x = x_min;
    for(i=1;i<n_left_right;i++)
    {
        double tmp_circle_radius = circle_radius - (double)(i*step_left);
        double sin_theta_2 = sin(wall_radius/tmp_circle_radius);
        double theta = 2.0 * asin(sin_theta_2);
        int n_circle = int(2.0*M_PI / theta) + 1;
        theta = 2.0*M_PI / (double)n_circle;
        for(j=0;j<n_circle;j++)
        {
            count ++;
            double angle = theta*j;
            y = sin(angle)*tmp_circle_radius;
            z = cos(angle)*tmp_circle_radius;
            fprintf(fout1, "%8d%12.4f%12.4f%12.4f%8.4f%8.4f%8.4f\n", count, x, y, z, 0.0, 0.0, 0.0);
            fprintf(fout, "%s%12.4f%12.4f%12.4f\n", "wall", x, y, z);
        }
    }
    // ---------------------------------------
    x = x_max;
    for(i=1;i<n_left_right;i++)
    {
        double tmp_circle_radius = circle_radius - (double)(i*step_left);
        double sin_theta_2 = sin(wall_radius/tmp_circle_radius);
        double theta = 2.0 * asin(sin_theta_2);
        int n_circle = int(2.0*M_PI / theta) + 1;
        theta = 2.0*M_PI / (double)n_circle;
        for(j=0;j<n_circle;j++)
        {
            count ++;
            double angle = theta*j;
            y = sin(angle)*tmp_circle_radius;
            z = cos(angle)*tmp_circle_radius;
            fprintf(fout1, "%8d%12.4f%12.4f%12.4f%8.4f%8.4f%8.4f\n",count, x, y, z, 0.0, 0.0, 0.0);
            fprintf(fout, "%s%12.4f%12.4f%12.4f\n", "wall", x, y, z);
        }
    }
  int wall_Num = count -  fill_Num;
    printf("wall_Num = %d\n",wall_Num);
    printf("total_Num = %d\n",count);
    fclose(fout);
    return 0;
}
2013-01-08 11:06
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 6楼 zhangfudong
是这样,我初学编程,好好学了C++,哪知道老大程序拿下来是个C啊,我顿时无语啊,我知道原理差不多,可是实在是语法有区别的啊,我真是搞不定了,只好求助了,各位路过的大侠啊高手啊帮帮小女子吧,万分感激啊
2013-01-08 11:27
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 8楼 yaobao
谢谢哦,果然是这样,我按照错误提示,全部定义在main之前,就可以运行了,谢谢你了。就是有些waring,无大碍了。结贴才发现,原来点醒我的是版主,版主威武

[ 本帖最后由 乐呵乐呵 于 2013-1-8 14:25 编辑 ]
2013-01-08 14:20
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 11楼 daniel_
谢谢回复,主要是加减乘除,循环的有点多,再加上定义的复杂了,所以看上去很长……
2013-01-08 14:26
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 13楼 yaobao
哇 离版主这么近 好激动哦  我不知道标准修订了  其实这个是我拿来做例子的  我的任务是自己写一个  而我只会C++ 如果现在去从头学一遍C  我木有勇气了……  不知道我自己写 会犯多少错呢……
2013-01-08 14:28
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 16楼 yaobao
恩呢 我正在拿运行的结果分析呢 激动持续中…… 偶一定继续努力 争取自力更生 楼主辛苦了 楼主高手就是我努力的目标啊 我一直觉得会计算机的人很牛掰滴  向往中……
2013-01-08 14:37
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 18楼 yaobao
不是哦 难道我说话的调调很东三省么
2013-01-08 14:44
快速回复:c语言程序,运行出错,但是我不知道怎么改,我只会点皮毛,高手指点啊 ...
数据加载中...
 
   



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

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