And, this is incorrect syntax:
Code:printf("Please enter the size of the array", size);
This is a discussion on size of array within the C Programming forums, part of the General Programming Boards category; 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);
Mac and Windows cross platform programmer. Ruby lover.
Quote of the Day
12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.
Amen brother!
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?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
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.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
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().
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
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?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
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).
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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!
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^