| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1319 人关注过本帖
标题:c语言程序,运行出错,但是我不知道怎么改,我只会点皮毛,高手指点啊,编译 ...
只看楼主 加入收藏
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:29 
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: 3Rank: 3
等 级:论坛游侠
帖 子:65
专家分:163
注 册:2011-10-18
收藏
得分:0 
出什么错?代码一贴,那么长,又没注释。
仔细一看,还没贴完整!!!


[ 本帖最后由 麦香 于 2013-1-8 10:44 编辑 ]

你们要进窄门,因为引向灭亡的门是宽的,路是大的,进去的人也多。
2013-01-08 10:43
乐呵乐呵
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
zhangfudong
Rank: 4
等 级:业余侠客
帖 子:119
专家分:212
注 册:2012-12-12
收藏
得分:0 
能写这么长的代码难道不会调试吗?
2013-01-08 11:18
乐呵乐呵
Rank: 1
等 级:新手上路
帖 子:15
专家分:3
注 册:2013-1-8
收藏
得分:0 
回复 6楼 zhangfudong
是这样,我初学编程,好好学了C++,哪知道老大程序拿下来是个C啊,我顿时无语啊,我知道原理差不多,可是实在是语法有区别的啊,我真是搞不定了,只好求助了,各位路过的大侠啊高手啊帮帮小女子吧,万分感激啊
2013-01-08 11:27
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:10 
变量声明要在函数开头的

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2013-01-08 11:38
XQwindow
Rank: 2
等 级:论坛游民
帖 子:121
专家分:64
注 册:2013-1-1
收藏
得分:0 
好长啊。。。

我不知道我能否当程序员,但我依然热爱编程!
2013-01-08 12:20
daniel_
Rank: 5Rank: 5
等 级:职业侠客
帖 子:212
专家分:307
注 册:2012-11-13
收藏
得分:0 
这个函数的需求是什么?
2013-01-08 13:57
快速回复:c语言程序,运行出错,但是我不知道怎么改,我只会点皮毛,高手指点啊 ...
数据加载中...
 
   



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

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