0

Okay I found the true culprit of my problems, the numbers were scanning in fine for those of you that were here before this edit.

void computeDataPoints(F_SELECT *fsPtr, int n,  double points[][n])
{
  int ix;  // for indexing points, i.e. columns of 2D array
  double x; // for incrementing the value of x
  double inc;  // incrementation value of x
  inc = (fsPtr->xf - fsPtr->x0)/(n-1);
  x= fsPtr->x0;

 // Setup loop that computes the points and stores in 2D array
  for (ix=0; ix<NUM_POINTS; ix = ix + 1)
   {
      points[X_IX][ix]=x;
      points[FX_IX][ix]=calcFx(x, &fsPtr->fNumber);
      x = x+ inc;
   }
}

I have no Idea how to fix this and have done some searching, if anyone knows how to make this pass properly I'd love you forever

sla2yer
  • 3
  • 4
  • Can you also show how you are checking if the values are stored correctly? – Ajay Brahmakshatriya Nov 09 '17 at 05:40
  • you haven't declared `selectFunction(&fselect);` before using it. And [`main` returns `int`, not `void`](https://stackoverflow.com/q/204476/995714) – phuclv Nov 09 '17 at 05:40
  • What do you mean by "enter point"? Do you mean you step over the function call to `selectFunction`? Then the debugger might actually be *outside* the `main` function so `fselect` is no longer in scope. – Some programmer dude Nov 09 '17 at 05:41
  • Unrelated to your problem, but your `do-while` loop exit test doesn't match your error condition. Specifically, if a number > 5 is entered, the error message will be printed, but the loop will still be exited. – Tom Karzes Nov 09 '17 at 05:42
  • 1
    It's a bit odd to use a double to store an integer. It works, but it would make a lot more sense to make `fNumber` an `int`. What will you do if someone enters 2.3? – Tom Karzes Nov 09 '17 at 05:48
  • @LưuVĩnhPhúc I left the declarations out, I added that in. It was declared just before the main. – sla2yer Nov 09 '17 at 05:52
  • @Someprogrammerdude by point I mean fnumber and a value for x0 and xf – sla2yer Nov 09 '17 at 05:52
  • @TomKarzes noted thanks – sla2yer Nov 09 '17 at 05:53
  • @sla2yer: So... Why are you trying to pass a pointer `&fsPtr->fNumber` to `calcFx` when it clearly expects an integer? – AnT stands with Russia Nov 09 '17 at 06:55
  • @AnT using a pointer for the int fNumber that is a variable in a globally declared structure F_SELECT – sla2yer Nov 09 '17 at 07:16
  • @sla2yer: Great. But `calcFx` does not want a pointer. It wants an integer. Why are you trying to pass a pointer? – AnT stands with Russia Nov 09 '17 at 07:23

2 Answers2

0

I'm just guessing here since there is really to little go on, but I think the situation is this:

You step through your code in your debugger. You stop at the call to scanf, when the debugger cursor is on the scanf line. That means the call hasn't happened yet. You need to step one more time for the scanf call to happen.

Another possibility is that you step past the scanf call, and the debugger cursor is now on the function closing }. Depending on the compiler and its generated code, that might mean that the variable sfPtr has gone out of scope and can not be examined reliably by the debugger.

The solution to both the above situation is to add another statement between the scanf call and the end of the function. For example a simple printf call to print the values:

    ...

    // Select a range of x for plotting
    printf("Select range of x for plotting (x0 and xf):");
    scanf("%lf %lf", &sfPtr->x0, &sfPtr->xf);

    // Print the values just entered
    printf("x0 = %f, xf = %f\n", sfPtr->x0, sfPtr->xf);

    // The function ends here
}

Besides printing the values, it also gives you an extra step in the debugger to check the values after the call to scanf.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • I was using the debugger watches, apparently improperly. However found this bug (as seen in the new edit). Thanks for the advice of using the extra printf – sla2yer Nov 09 '17 at 06:50
0

I FOUND IT

points[FX_IX][ix]=calcFx(x, &fsPtr->fNumber);

needs to be

points[FX_IX][ix]=calcFx(x, fsPtr->fNumber);

Thank you to everyone who tried to help me when I was looking in the wrong spot

sla2yer
  • 3
  • 4