And, this is incorrect syntax:
Code:printf("Please enter the size of the array", size);
And, this is incorrect syntax:
Code:printf("Please enter the size of the array", size);
Mainframe assembler programmer by trade. C coder when I can.
would free(array); be in main or function?
using system("pause") and gerchar() is that the same thing?
does the program stop so that I can see whats on the screen?
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
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; }
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).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
the reason i put sizeof(double) is because the numbers that will be put into the array will be doubles. is that incorrect?