And, this is incorrect syntax:
Code:printf("Please enter the size of the array", size);
Printable View
And, this is incorrect syntax:
Code:printf("Please enter the size of the array", size);
would free(array); be in main or function?
Once you free the memory, you can't use it anymore. So it must be done when you're finished with it. What does that tell you?
using system("pause") and gerchar() is that the same thing?
does the program stop so that I can see whats on the screen?
Yes.
This is just one of many methods to do it. If you have a debugger, you can just set a breakpoint at the last line.
In Visual Studio, you can run without debugging and it will hold the window open.
thanks
this is what i have so far and there is an enternal error
what am i doing wrong?
Code:#include <stdio.h>
#include <stdlib.h>
int* makeAnArray(int);
main (){
int size=0;
printf("Please enter the size of the array", size);
scanf("%i", &size);
makeAnArray(size);
array(free);
getchar();
}
int* makeAnArray(int size){
int* array;
array=calloc(size,sizeof(int));
return array;
}
Huh? You should be calling free with array as an argument, not call a function array() with the argument free, first of all.
Second, you are not "receiving" the array returned by makeAnArray() [as I pointed out in a previous post].
--
Mats
I repeat:
Code:int main (){
And then:Code:printf("Please enter the size of the array");
Don't omit variable names in prototypes.Code:int* makeAnArray(int size);
And lastly:
You let the return (your pointer!) from makeAnArray go lost. Without a trace. Thus the memory is leaked. Never to be found ever again until your app exits. Very bad.Code:makeAnArray(size);
array(free);
And what's "array(free)"?
You free using the function free().
here is what i have. i am still getting major error????Code:
#include <stdio.h>
#include <stdlib.h>
int* makeAnArray(int size);
int main (){
int size=0;
printf("Please enter the size of the array");
scanf("%i", &size);
makeAnArray(size);
free(makeAnArray);
getchar();
}
int* makeAnArray(int size){
int* array;
array=calloc(size,sizeof(double));
return array;
}
Do tell how you're supposed to free a function?
You need to assign the pointer returned by makeAnArray() to a pointer to int, and then free that pointer to int. Also the second argument to calloc() should be a sizeof(int), not sizeof(double).
the reason i put sizeof(double) is because the numbers that will be put into the array will be doubles. is that incorrect?
Then you need to allocate a pointer to double! You can't allocate int and use doubles!