Thread: Help with qsort

  1. #16
    Registered User
    Join Date
    Apr 2010
    Posts
    11
    Thanks, so something like this?

    Code:
    int i, in;
    
    Int *array;
    
        do
        {
            fscanf(infile, "%d", &in); /* read from infile into int variable in */
            
            array = malloc(sizeof(in));
            
            if (!feof(infile))  /* only process in if didn't reach end of file */
           {
                for (i=1; i<=sizeof(in), i++)
                int array[i]=in; /* process in */
           }
        } while(!feof(infile));
        fclose(infile);

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Not really. You should put the new value in just once, not four times. And as you read more, you will probably need to extend your "array" past one value (which is all you ever have at the moment).

  3. #18
    Registered User
    Join Date
    Apr 2010
    Posts
    11
    I don't understand, where is four times coming from?

    and to past one vaule, as "i" is increasing, it store "in" to different part of array,
    like array[1], array[2] so on.

    please help!

  4. #19
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You are not making any attempt to understand how to write this program. You're using the 1 billion monkeys approach whereby you type up 1 billion different versions of the function, in the hope that one of them comes out right.

    Stop doing that! Engage your brain and think for a moment... Why would you need a for-loop inside your while loop? Each time through the loop you read in one value, and place that one value into your array.

    You equally don't have a clue how to use malloc to further your progress here. Forget that for now, and see if you can get the rest right using just an array that should be more than large enough to hold whatever you want to read in at the moment. Perhaps 10000 items.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An interesting problem of qsort()
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 03-05-2008, 12:09 PM
  2. qsort() in Array of Pointer to String
    By vb.bajpai in forum C Programming
    Replies: 8
    Last Post: 06-16-2007, 04:18 PM
  3. C++ link error with qsort
    By bvnorth in forum C++ Programming
    Replies: 7
    Last Post: 10-24-2003, 02:22 AM
  4. qsort - newbie trouble with pointers
    By aze in forum C Programming
    Replies: 4
    Last Post: 03-10-2003, 03:38 PM
  5. Qsort
    By Tombear in forum C Programming
    Replies: 1
    Last Post: 10-28-2001, 09:06 AM