memcpy麻烦与C

时间:2018-10-05 02:21:37

标签: c memcpy

到目前为止,所有程序都应在该程序中运行,除非我在memcpy方面遇到一些问题。该程序应该获取数字,对它们进行排序,然后总计。它应该复制结果并存储它们,但是我不确定我做错了什么。任何帮助将不胜感激。预先感谢!

#include <stdio.h>  
#include <stdlib.h> 
#include <string.h> 

#define MINIMUM_QUANTITY  2      
#define MAXIMUM_QUANTITY  200            
#define QUIT              0      

void print_heading();
void print_instructions();
int  get_quantity();
void get_data(float *dataStart, int quantity);
void sort_data(float *dataStart, int quantity);
void print_data(float *dataStart, int quantity );
float sum_data(float *dataStart, int quantity);
void print_total(float total);

int main()
{
   int   quantity;
   float *data;

   {
      getData(p_data, quantity);
      sortData(p_data, quantity);
      printData(p_data, quantity);
      printTotal(sum_data(p_data, quantity));


      free(p_data);
   }


   return 0;
}

int quantity()
{
   int choice;

   do
   {
      printf("\nHow many data values are there (%d to %d, %d=quit): ",
             MINIMUM_QUANTITY, MAXIMUM_QUANTITY, QUIT);
      scanf ("%d", &choice);
   }
   while((choice > MINIMUM_QUANTITY && choice < MAXIMUM_QUANTITY)
         && choice != QUIT);
   return choice;
}

void getData(float *dataStart, int quantity)
{
   float *p_data;

   for(data = dataStart; (data - dataStart) <= quantity; data++)
   {
      printf("Enter data value %f: ", data);
      scanf ("%f", data);

   }
   return;
}

void sortData(float *dataStart, int quantity)
{
   float *data,
         *sort, 
         *sortStart,          
         *biggest;    

   for(sort = sortStart; (sort - sortStart) < quantity; sort++) 
   {
      *sort = 0.0f;
      for(data = dataStart; (data - dataStart) < quantity; data++)
      {
         if(*data >= *sort)
         {
            *biggest = *data;
            *sort    = *biggest;
         }
      *biggest = 0.0f;
      }
   }
   memcpy(data, sort, sortStart);     

   free(sort);

   return;
}

void printData(float dataStart, int quantity)
{
   float data;


   for(data = dataStart; (data - dataStart) < quantity; data++)
   {
      printf("                     %.2f", *data);
   }

   return;
}
float sumData(float *dataStart, int quantity)
{
   float *data,
         dataTotal = 0;

   for(data =  dataStart; (data - dataStart) < quantity; pdata++)
      dataTotal += *data;
    return dataTotal;
}

void total(float total)
{
   printf("\n                       %f", total);
   return;
}

0 个答案:

没有答案