Hi,
I'm pretty new to this, so bear with me.
I'm having a few problems accessing data in a void *. Basically, we had to convert a program that created and performed functions on a linked list of integers to one that used void *, and then could handle any data type.
This is part of my main.c (I'm running it redirecting the input to a file that contains a list of numbers..."main.x < numbers"):
Code:
int main() {
int cur_size, *number_read;
void *occurrences, *large_value, *large_key, **key_list;
Table list= create();
while (!feof(stdin)) {
scanf("%d ", number_read);
if (lookup(list, number_read, &occurrences) == 1) {
delete(&list, number_read);
insert(&list, number_read, occurrences); /* needs to be occurrences + 1 */
} else insert(&list, number_read, (void *)1);
}
All of the functions it calls I'm pretty sure work, because they've worked in tests that I haven't written the main function. they work with strings, doubles, ints, etc.
My problem is with the insert function. First, is the "else insert(...)" call correct? It should be inserting a pointer to the integer value 1. Second, how do I send in a pointer to the integer value stored at *occurrences + 1?
The call to lookup(...) in the if will store a value in occurrences if it finds number_read in the list.
I've tried casting it to int *, then dereferencing it but I get a seg fault anytime I try to do that.
Any help is awesome...I know this post is probably extremely confusing but I don't have a better way to write it...
Thanks in advance!