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?
Printable View
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?
makeAnArray returns a value. You aren't storing it in a variable.
If you want to work with doubles, then allocate doubles.
If you want to work with integers, then allocate integers.
Don't do anything else. Change the function accordingly.
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
Again, you can't free a function!
makeAnArray is a function!
You didn't allocate it with malloc or calloc, so you can't free it!
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.
Indeed. You need to go back to basics. You don't seem to understand much about C, at all.
Go back to reading about variables, functions, arguments and return types. Then try again.