For a task I'm supposed to read in integers from the command line and then sum them up after putting them onto the heap.Now, I'm quite rusty with using malloc and strings and whatnot because we're pretty new to them, but I've had some experience with putting string of characters onto the heap.
This is my first time putting integers onto the heap though, and I'm very stuck.
What I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int *heap(int argc, char *argv[]);
int sum();
int main(int argc, char *argv[]) {
//int sum = 0;
int *value = NULL;
if (argc > 1) {
value = heap(argc, argv);
if (value == NULL) {
fprintf(stderr, "Memory Error\n");
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
int *heap(int length, char *argv[]) {
int *value = NULL;
value = malloc(length * sizeof(int));
if (value != NULL) {
//INSERT HERE
}
return value;
}
I'm completely clueless with what to do in the comment that says INSERT HERE. The argv values are strings of characters (even if integers are input) so I can't just put them onto the heap... Any advice?