السؤال:
Write a program populate which allocates from the heap any array of doubles with a default max size of 50 and populate its elements,
the standard input: populate 10 will allocate an array of 10 doubles from the heap and read a max 10 elements.
الكود:
#include <stdio.h>
#include <stdlib.h>
#define max 50
int main(int argc, char *argv[])
{
double *arr;
if ( argc == 1 )
{
arr = malloc(sizeof(double) * max );
printf ("Enter 50 doubles: \n");
int i;
for (i=0; i<max; i++){
scanf ("%lf",arr);
}
}
else
{
arr = malloc(sizeof(double) * *(argv[1]));
printf ("Enter %s doubles: \n",argv[1]);
int g;
for (g=0; g<*(argv[1]); g++){
scanf ("%lf",arr[g]);
}
}
}ما الخطأ ؟
المشكله بالـ run و ليس الـ compile
انتصف كورس البرمجه و الى الآن لم نتقن اللغه و السبب هيئة التدريس :)
فأرجو المساعده ..