finishing up the sorting program

This is a discussion on finishing up the sorting program within the C Programming forums, part of the General Programming Boards category; I think there's bug in my program When I put in letter it prints 0. but when i put in ...

  1. #1
    jk
    Guest

    finishing up the sorting program

    I think there's bug in my program
    When I put in letter it prints 0.
    but when i put in numbers it says core error.
    what is wrong with this program?

    /* Program that utilizes simple functions illustrating call-by-reference and call-by-valye */

    #include <stdio.h>
    void swap(double*, double*);
    int read5(double*, double*, double*, double*, double*);
    double sort5(double*, double*, double*, double*, double*);
    double print5(double*, double*, double*, double*, double*);

    int main(void)
    { /* begin main */
    /* Declaration */
    double z, z1, z2, z3, z4;
    int checknum = 1;

    /* Check Scanf */
    while(checknum > 0)
    { /* start while */
    if (checknum == 0)
    { /* begin if */
    printf("Ends Program");
    checknum = -1;
    } /* end if */
    else
    { /* begin else */
    checknum = read5(&z, &z1, &z2, &z3, &z4);
    sort5(&z, &z1, &z2, &z3, &z4);
    print5(&z, &z1, &z2, &z3, &z4);
    } /* end else */

    } /* end while */

    }


    int read5(double *i, double *j, double *k, double *l, double *m)
    {
    int check;

    check = scanf("%lf%lf%lf%lf%lf", *i, *j, *k, *l, *m);
    return check;

    } /* end read5 */

    double sort5(double *u, double *v, double *w, double *x, double *y)
    {
    int index = 1;

    if(*u > *v)
    {
    swap(u, v);
    index = 2;
    }

    if(*u > *w)
    {
    swap(u, w);
    }

    if(*v > *w)
    {
    swap(v, w);
    }

    if(*w > *x)
    {
    swap(w, x);
    }


    }

    double print5(double *i, double *j, double *k, double *l, double *m)
    {
    printf("%lf %lf %lf %lf %lf", *i, *j, *k, *l, *m);
    }

    void swap(double *largenum, double *smallnum)
    {
    int tmp;
    tmp = *largenum;
    *largenum = *smallnum;
    *smallnum = tmp;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I had a horrible dream... it was a nightmare on a grand scale... No, wait, it's just me reading your code without the [c0de] [/code] tags...

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    I hate to break it to you quzah, but it doesn't get much better when the code is formatted.

    >what is wrong with this program?
    Quite a bit, but the access violation is caused by this line:
    Code:
    check = scanf("%lf%lf%lf%lf%lf", *i, *j, *k, *l, *m);
    It should be something more like this
    Code:
    check = scanf ( "%lf %lf %lf %lf %lf", &i, &j, &k, &l, &m );
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 11:58 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 10:49 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21