Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 写入函数以输出分数直方图_C_File_Structure_Histogram - Fatal编程技术网

C 写入函数以输出分数直方图

C 写入函数以输出分数直方图,c,file,structure,histogram,C,File,Structure,Histogram,对于此直方图函数的算法有什么建议吗?您的代码正在写入正确数量的星号,但是您运行此代码的控制台窗口不够宽,无法在不换行的情况下显示该数量的星号。您可以更改控制台窗口的宽度。我不确定您正在运行哪个操作系统,因此我无法指导您完成更改控制台窗口宽度的过程 不过,改变比例是一个简单的选择。只要改变你的循环,让它以分数除以任何刻度结束。例如,如果希望一个星号代表两个星号: Enter the file name: in.txt name is Ada Lovelace and score

对于此直方图函数的算法有什么建议吗?

您的代码正在写入正确数量的星号,但是您运行此代码的控制台窗口不够宽,无法在不换行的情况下显示该数量的星号。您可以更改控制台窗口的宽度。我不确定您正在运行哪个操作系统,因此我无法指导您完成更改控制台窗口宽度的过程

不过,改变比例是一个简单的选择。只要改变你的循环,让它以分数除以任何刻度结束。例如,如果希望一个星号代表两个星号:


    Enter the file name: in.txt
    name is Ada Lovelace and score is 66
    name is Linus Torvalds and score is 75
    name is Peter Norton and score is 82
    name is Ken Thompson and score is 82
    name is Steve Wozniak and score is 79
    name is Marc Andreessen and score is 60
    name is Donald Knuth and score is 60
    name is Adele Goldberg and score is 71
    name is Grace Hopper and score is 82
    name is Bill Joy and score is 91
    name is Andrew Tanenbaum and score is 71
    name is Brian Kernighan and score is 72
    Read in 12 data records
    60
    60
    66
    71
    71
    72
    75
    79
    82
    82
    82
    91
    size is: 12
    73.50

    60:************************************************************
    60:************************************************************
    66:******************************************************************
    71:***********************************************************************
    71:***********************************************************************
    72:************************************************************************
    75:***************************************************************************
    79:*****************************************************************************
    **
     82:*****************************************************************************
*****
    82:*****************************************************************************
*****
    82:*****************************************************************************
*****
    91:*****************************************************************************
**************

74.25

实际上,代码并不打算有很多星号,例如60重复2次,所以输出应该是60**,但在我的输出中,它打印出每行60个星号

    Enter the file name: in.txt
    name is Ada Lovelace and score is 66
    name is Linus Torvalds and score is 75
    name is Peter Norton and score is 82
    name is Ken Thompson and score is 82
    name is Steve Wozniak and score is 79
    name is Marc Andreessen and score is 60
    name is Donald Knuth and score is 60
    name is Adele Goldberg and score is 71
    name is Grace Hopper and score is 82
    name is Bill Joy and score is 91
    name is Andrew Tanenbaum and score is 71
    name is Brian Kernighan and score is 72
    Read in 12 data records
    60
    60
    66
    71
    71
    72
    75
    79
    82
    82
    82
    91
    size is: 12
    73.50

    60:************************************************************
    60:************************************************************
    66:******************************************************************
    71:***********************************************************************
    71:***********************************************************************
    72:************************************************************************
    75:***************************************************************************
    79:*****************************************************************************
    **
     82:*****************************************************************************
*****
    82:*****************************************************************************
*****
    82:*****************************************************************************
*****
    91:*****************************************************************************
**************

74.25
   for(j = 0; j < list[i].score / 2; j++)
   {
      putchar('*');
   }
   for(j = 0; j < list[i].score / 2; j++)
   {
      putchar(':');
   }

   if (list[i].score % 2 == 1) {
      putchar('.');
   }