Problem programming :s

This is a discussion on Problem programming :s within the C Programming forums, part of the General Programming Boards category; Hi everyone, First of all, since I'm Portuguese I may do some grammatical errors, so sorry for that. I'm programming ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    7

    Problem programming :s

    Hi everyone,

    First of all, since I'm Portuguese I may do some grammatical errors, so sorry for that.

    I'm programming in C a program to order a structure. This program is a work that I need to do for Numerical Analyses.

    I don't know why, but it works great sometimes (with some points), but sometimes it acts backwards, instead of crescent order, it do decrescent order.

    this is my function:

    Code:
    void ordenar_pontos (interpolacao polacao[], int pola)
    {
        int ini, av;
        interpolacao temp;
    
        for(ini = 0;ini < pola-1; ini++)
        {
            for(av=ini+1;av < pola; av++)
            {
                if(polacao[av].x > polacao[ini].fx)
                {
                    temp.x = polacao[ini].x;
                    temp.fx = polacao[ini].fx;
                    polacao[ini].x = polacao[av].x;
                    polacao[ini].fx = polacao[av].fx;
                    polacao[av].x = temp.x;
                    polacao[av].fx = temp.fx;
                }
            }
        }
    
    }
    The int "pola" is the number of points in "polacao", so it goes to polacao[pola-1].
    Last edited by RA-3000; 05-10-2010 at 02:34 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I doubt that it's meaningful to be comparing the x component of polacao[av] with the fx component of polacao[ini].

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    Also, to save missing struct members, or getting them mixed up.
    Code:
                    temp = polacao[ini];
                    polacao[ini] = polacao[av];
                    polacao[av] = temp;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    7
    Quote Originally Posted by tabstop View Post
    I doubt that it's meaningful to be comparing the x component of polacao[av] with the fx component of polacao[ini].
    Thank you I didn't noticed that

    Quote Originally Posted by Salem View Post
    Also, to save missing struct members, or getting them mixed up.
    Code:
                    temp = polacao[ini];
                    polacao[ini] = polacao[av];
                    polacao[av] = temp;
    I didn't know that I could do that, thank you
    Last edited by RA-3000; 05-10-2010 at 02:29 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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