J
Juggernaut
I have a program that compiles without errors, but when I run it I get a
segment fault.
I have managed to trace where it happens, but since im new to C I don't know
how to fix this or how I did it wrong.
In main lets say I have 2 variables var1 and var2 that has values that I
want to pass to a method for calculations with them. But I want to work with
them later from main so I thought I'd make them pointers.
So I called them to a method so: method(&var1, &var2)
and the method receives them so: void method(int *var1, *var2)
All this works..but when I try to get the numbers that are supposed to be in
var1 and var2 I get some long crazy numbers (like -1218520428) and I am
guessing these are the address to the int I want?
And the segment error happens when I use these in an array
(array[var1][var2]) because it gets extremely out of bounds.
But how do I get the values and not the address?
I tried grabbing them from the pointer and placing it in a new variable like
this: int var = (int)var1
But the new variable also has the huge address value
So my question is, what am I doing wrong? How to I access the actual value
thats in main from the other method and not the address?
I need the number to calculate with, and the starting number has to be
created in main.
Hope someone can help.
-Juggernaut
P.S. I can post the actual code, but I thought It wouldn't be necessary
since I know whats wrong, but just not how I do it right.
segment fault.
I have managed to trace where it happens, but since im new to C I don't know
how to fix this or how I did it wrong.
In main lets say I have 2 variables var1 and var2 that has values that I
want to pass to a method for calculations with them. But I want to work with
them later from main so I thought I'd make them pointers.
So I called them to a method so: method(&var1, &var2)
and the method receives them so: void method(int *var1, *var2)
All this works..but when I try to get the numbers that are supposed to be in
var1 and var2 I get some long crazy numbers (like -1218520428) and I am
guessing these are the address to the int I want?
And the segment error happens when I use these in an array
(array[var1][var2]) because it gets extremely out of bounds.
But how do I get the values and not the address?
I tried grabbing them from the pointer and placing it in a new variable like
this: int var = (int)var1
But the new variable also has the huge address value
So my question is, what am I doing wrong? How to I access the actual value
thats in main from the other method and not the address?
I need the number to calculate with, and the starting number has to be
created in main.
Hope someone can help.
-Juggernaut
P.S. I can post the actual code, but I thought It wouldn't be necessary
since I know whats wrong, but just not how I do it right.