Thread: Pointer help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2020
    Posts
    31

    Pointer help

    Hello, I am a self taught in C, and new at that. I think its a stretch to call myself a programmer.

    In the first snippet, I pass the variable seed_temp to the psat function and it works perfectly.

    Code:
    while (index < 101)
    {
      float seed_temp = 20;
      do {
        psat1 = calc_psat(eA, eB, eC, seed_temp, gamma_e, x1);
        psat2 = calc_psat(wA, wB, wC, seed_temp, gamma_w, x2);
        seed_temp = seed_temp + 0.0001;
      } while (psat1 + psat2 < 760);
      boil_pt[index] = seed_temp;
    }

    In the 2nd snippet I'm trying to pass previously calculated seed_temp rather than start at a value of 20 each pass through the do while loop. However,in the 2nd snippet using a pointer, the do while loop does not iterate to satisfy the "< 760" condition.

    Code:
    float seed_temp = 70;
    float *p_seed_temp;
    p_seed_temp = &seed_temp;
    
    while (index < 101)
    {
    do {
    psat1 = calc_psat(eA, eB, eC, &seed_temp, gamma_e, x1);
    psat2 = calc_psat(wA, wB, wC, &seed_temp, gamma_w, x2);
    *p_seed_temp += 0.0001;
    }
    while (psat1 + psat2 < 760);
    boil_pt[index] = seed_temp;
    I hope I've explained the problem clearly. I cut some code out for brevity including an obvious curly bracket. But both programs compile and run. There might be other errors but the do while loop not executing is the current one.

    Thank you for any insight.

    gave up trying to fix code tags
    Last edited by Buckeye Bing; 09-09-2020 at 01:43 PM. Reason: too many code tags

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-05-2018, 12:14 AM
  2. Replies: 4
    Last Post: 08-18-2015, 03:13 PM
  3. Replies: 8
    Last Post: 03-01-2015, 12:39 AM
  4. Replies: 3
    Last Post: 10-30-2009, 04:41 PM
  5. Replies: 4
    Last Post: 08-27-2007, 11:51 PM

Tags for this Thread