what would i have to keep as an int since size is going into the function as an int???
or could i just make everyhting a double?
what would i have to keep as an int since size is going into the function as an int???
or could i just make everyhting a double?
i changed everything over to doubles
not when i run the program i get this error box:
Windows has triggered a breakpoint in Assignment 8.1.exe.
This may be due to a corruption of the heap, which indicates a bug in Assignment 8.1.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while Assignment 8.1.exe has focus.
The output window may have more diagnostic information.
Code:#include <stdio.h> #include <stdlib.h> double* makeAnArray(double size); int main (){ int size=0; printf("Please enter the size of the array"); scanf("%i", &size); makeAnArray(size); free(makeAnArray); getchar(); } double* makeAnArray(double size){ int* array; array=calloc(size,sizeof(double)); return array; }
What the red bit does is give the function free() the address of makeAnArray - that is not a piece of memory that has been allocated through malloc/calloc, so it will not "go down well".Code:#include <stdio.h> #include <stdlib.h> double* makeAnArray(double size); int main (){ int size=0; printf("Please enter the size of the array"); scanf("%i", &size); makeAnArray(size); free(makeAnArray); getchar(); } double* makeAnArray(double size){ int* array; array=calloc(size,sizeof(double)); return array; }
--
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 changed that to free(array)
but the problem i am having with that is
error C2072: 'array' : initialization of a function
here is the code. How can i fix that
Code:#include <stdio.h> #include <stdlib.h> double* makeAnArray(double size); int main (){ int array()={0}; int size=0; printf("Please enter the size of the array"); scanf("%i", &size); makeAnArray(size); free(array); getchar(); } double* makeAnArray(double size){ int* array; array =calloc(size,sizeof(double)); return *array; }
OMG. I'm totally invisible today. Why am I wasting my time.
Mainframe assembler programmer by trade. C coder when I can.