Thread: structures

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    56

    Question structures

    okay im supposed to read from a file and store data in a struct array ,but i must insert in place at the time of reading.i have sucessfully read from the file just my insertion function needs some help. this is what i have so far
    Code:
    //struct declaration
    typedef struct{
            char fname[15];
            char lname[15];
            int accnum;
            double balance;
            }Account;
    
    //how i call it
     fscanf(in,"%d",&temp);
        while(temp!=-1){
                    type[i].accnum=temp;
                    fscanf(in,"%lf %s %s",&type[i].balance,&type[i].fname,&type[i].lname);
                    insertinplace(type[i],type,0,1000);
                    i++;
          fscanf(in,"%d",&temp);
         
         }
    
    
    
    
    //function
     void insertinplace(Account set,Account list[MAX],int m,int n){
              int k=n;
              while(k>=m && set.accnum < list[k].accnum){
                         list[k+1]=list[k];
                         --k;
                         }
              list[k+1]=set;
              }
    i just need a little -> in the corect direction.thanks for any help i can get

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    56
    correction
    Code:
    //how i call it
     fscanf(in,"%d",&temp);
        while(temp!=-1){
                    type[i].accnum=temp;
                    fscanf(in,"%lf %s %s",&type[i].balance,&type[i].fname,&type[i].lname);
                    insertinplace(type[i],type,0,i);
                    i++;
          fscanf(in,"%d",&temp);
         
         }
    had this not the other

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    56

    solved : )))

    how cool i solved my own problem.how i had it i was comparing it with the same value i read so it would never sort.i needed to compare it with it's predecessor so
    k=n-1;
    lol so simple hehe yay.tnx me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures within Structures
    By Misko82 in forum C Programming
    Replies: 2
    Last Post: 08-27-2007, 12:25 AM
  3. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM