Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My program works fine, I just need help figuring out why keyword malloc is getti

ID: 3625509 • Letter: M

Question

My program works fine, I just need help figuring out why keyword malloc is getting underlined red with a the warning statement: a value of type void cannot be used to intialize an entity of type int. How can I correct this?

 

 

 

Thank you.

 

 

 

 

 

 

 

#include

 

 

 

#include

 

 

 

#pragma warning(disable:4996)

 

 

 

 

 

 

 

int input(int* );

 

 

 

void print(int*,int);

 

 

 

void sort(int*,int);

 

 

 

int maxx(int*,int);

 

 

 

int minn(int*,int);

 

 

 

void printminmax(int,int);

 

 

 

void explanation();

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

int main()

 

 

 

{

 

 

 

      

 

 

 

int max=200,n,big,small;

 

 

 

 

 

 

 

int  *hold = malloc(sizeof(int)*max);

 

 

 

 

 

 

 

explanation();

 

 

 

n=input(hold);

 

 

 

sort(hold,n);

 

 

 

print(hold,n);

 

 

 

big=maxx(hold,n);

 

 

 

small=minn(hold,n);

 

 

 

printminmax(big,small);

 

 

 

return 0;

 

 

 

}

 

 

 

 

 

 

 

void explanation()

 

 

 

{

 

 

 

       printf("Enter numbers only into the array. ");

 

 

 

       printf("When you are done entering numbers press Control and Z to signal ");

 

 

 

       printf("end-of-file. ");

 

 

 

       printf("The numbers will then be sorted in ascending order and dispalyed. ");

 

 

 

       printf("The largest and smallest numbers will also be displayed. ");

 

 

 

 

 

 

 

      

 

 

 

}

 

 

 

 

 

 

 

void sort(int* a,int n)

 

 

 

{int i,j,t;

 

 

 

for(i=0;i

 

 

 

      for(j=i+1;j

 

 

 

           if(*(a+i)>*(a+j))

 

 

 

               {t=*(a+i);

 

 

 

               *(a+i)=*(a+j);

 

 

 

               *(a+j)=t;

 

 

 

               }

 

 

 

}

 

 

 

 

 

 

 

 

 

 

 

void printminmax(int b,int s)

 

 

 

{

 

 

 

       printf("The smallest number is %d The largest number is %d ",s,b);

 

 

 

}

 

 

 

 

 

 

 

 

 

 

 

int minn(int* a ,int n)

 

 

 

{int i,m;

 

 

 

m=*a;

 

 

 

for(i=1;i

 

 

 

    if(*(a+i)

 

 

 

        m=*(a+i);

 

 

 

return m;

 

 

 

}

 

 

 

 

 

 

 

 

 

 

 

int maxx(int* a ,int n)

 

 

 

{int i,m;

 

 

 

m=*a;

 

 

 

for(i=1;i

 

 

 

    if(*(a+i)>m)

 

 

 

        m=*(a+i);

 

 

 

return m;

 

 

 

}      

 

 

 

 

 

 

 

 

 

 

 

void print(int *a,int n)

 

 

 

{int i;

 

 

 

printf("The array ");

 

 

 

for(i=0;i

 

 

 

   printf("%d  ",*(a+i));

 

 

 

printf(" ");

 

 

 

 

 

 

 

 

 

 

 

 

 

 

int input(int *array)

 

 

 

{ int i=0;

 

 

 

printf("Enter the array: ");

 

 

 

printf("Enter element %d: ",i+1);

 

 

 

while(scanf("%d",array+i)==1)

 

 

 

     {i++;

 

 

 

      printf("Enter element %d: ",i+1);

 

 

 

      }

 

 

 

return i;

 

 

 

}

 

 

 

 

Explanation / Answer

int *hold = (int *) malloc(sizeof(int)*max); cast it back to (int *) . This will solve the problem // Please rate this if it helped you :)