problems with sorting the arrays which are in already in file

This is a discussion on problems with sorting the arrays which are in already in file within the C Programming forums, part of the General Programming Boards category; problem with buble sort Code: printf("\n STUDENT ID No. OF SUBJECTS STATUS FEES DUE\n"); printf("\n-----------------------------------------------\n"); printf(" %d %d %c $%6.2f ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    1

    Exclamation problems with sorting the arrays which are in already in file

    problem with buble sort
    Code:
    printf("\n  STUDENT ID  No. OF SUBJECTS  STATUS  FEES DUE\n"); printf("\n-----------------------------------------------\n");
    printf("  %d         %d            %c     $%6.2f   \n", students[i].Student_ID, students[i].nose, students[i].status, students[i].Total_fees);
    
    out_file = fopen("STUDENT.DAT", "a");
    
             if(out_file ==(FILE *) NULL)
    {
       printf("\nFailed to open file\n");
      }
      else
      {
       printf("\nSuccessfully write to the file STUDENT.\n");
      }
    
    
        printf("\nDo you want continue?  ");
        scanf("%c", &Answer);
          fflush(stdin);
      }
       while (Answer =='y' || Answer =='Y');
    
       fprintf(out_file,"%d %d %c %6.2f\n", students[i].Student_ID, students[i].nose, students[i].status, students[i].Total_fees);
          fclose(out_file);
    
       in_file = fopen("STUDENT.dat", "r");
    
       if (in_file != NULL)
       {
       printf("\nSuccessfully open the file for reading.\n");
       }
       else
       {
       printf("\nFailed to open the data file.\n");
       }
    
       fscanf(in_file,"%d %d %c %f", &students[i].Student_ID, &students[i].nose, &students[i].status, &students[i].Total_fees);
       rewind(in_file);
       while (fscanf(in_file,"%d %d %c %f", &students[i].Student_ID, &students[i].nose, &students[i].status, &students[i].Total_fees) != EOF)
            
         moves = 1;
          students[i].Student_ID=0;
       	while (moves > 0)
                {
                	moves = 0;
                   students[i].Student_ID= 0 ;
    while (students[i].Student_ID < 100)
                {
                	if(students[i].Student_ID > students[i+1].Student_ID)
                   	{
                   	temp = students[i+1].Student_ID;
                    students[i+1].Student_ID = students[i].Student_ID;
                      students[i].Student_ID = temp;
                      moves++;
                   	}
                   }
                }
    
    
    
          for (i = 0; i< RECORDS; i++)
    
       fprintf(out_file,"%d %d %c %6.2f\n", students[i].Student_ID, students[i].nose, students[i].status, students[i].Total_fees);
       fclose(in_file);
    
       getch();
    }

    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >problem with buble sort
    Yes, yes there is a problem with bubble sort.

    >fflush(stdin);
    This is a problem too.

    Could you be more specific as to what is happening, what you want, and post some compilable code in code tags for us? Otherwise we'll just nitpick at every problem we see, driving you insane.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    First of all no one is gonna read that ?? use code tags to post ur code post it again but this time using code tages e.g of a code tag

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
    
          system("PAUSE");
          return 0;
    }
    how to use code tags do this [code] your code in hear [\code]

    instead of a \ use a / i did that so i could show u the syntax of whatever
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 01:44 PM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 08:01 PM

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