Question

    for( k = 0; k < CycleCount;k++)
    {
        //make Org data
        int* Data = MakeData(DataCount[i]);
  ......

the function look like this one. i think this is right. so ...

  int* MakeData(int DataCount)
  {
        //
   int* Data=(int*)malloc(DataCount*sizeof(int));
   int i;
   for( i=0; i<DataCount; i++)
   {
      //
      Data[i] = rand()%DataCount +1;
   }
   return Data;
 }

i dont know why this didn't work.

what shoud i have to do???

Was it helpful?

Solution

When the C compiler finds a function call without having seen a function prototype it assumes a function that returns an int.

You should tell the compiler the correct function signature with the "function prototype":

int* MakeData(int DataCount);

This should be placed in a .h file that will be included in all compilation units that call or define the function.

If you have a static function, that is visible only in the current compilation unit, you can place the prototype (incl. static) before all functions in that file.

Further you should never cast the return from malloc. It returns a void*. In the language C this can be converted to any other pointer type. You get the correct prototype when you #include <stdlib.h>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top