I have a function of the form:
Code:
float function(string[],i) {
/*multiple operations, each with some output...and I know this works, as I have already ran it outside of this function and debugged it by printing each output*/
switch(i) { /* i equals 1,2, or 3, and selects the output of the function*/
case 1: return (x); /* x is a float */
break;
case 2: return (n); /* n is an integer*/
break;
case 3: return (c); /*c is a char
break;
default: printf("Inavlid request\n");
}
} /*end function*/
int main () {
/*input string and i*/
float answer=function(string,i);
printf("Answer=%f\n",answer);
return 0;
}
I'm guessing the fault is because I have declared function as a float, but in certain cases, the function is trying to return an int or char. (mind you, I still get this error when I select i=1, returning the float variable). I have tried declaring function as void, but got some compile-time errors.
Is this problem likely to be causing my segmentation error or will it be something else?
How can I ammend this?
thanks