Closed Thread
Results 1 to 4 of 4

Thread: Just an idea

  1. #1
    hbk
    hbk is offline Learning Programmer
    Join Date
    Mar 2010
    Posts
    68
    Rep Power
    0

    Just an idea

    I want to scan a number from a file and use it as means as a checkpoint to another file. The truth is i am writing data to a file based on id numbers and i want when the compiler is closed and reopened the data can continue be entered based on the last id number entered.

    I am using two files to carry out such task, one file hold all the information and the other i want just to store the last id number entered by the user.

    So when the user runs the program another time it shuld read data from the second file and use it as a chechpoint.

    Code:
    void addrecord(void)
    {
         system("color 2"); 
         
         FILE *cust;   
             
         customer1 = fopen("customer1.txt","a+");
         cust=fopen("temp.txt","a+");
        
         int num=0,x;
         int base=0;
         
         int regis=1000;
         int regis2=1000;
              
         fscanf(cust,"%d",&info.regis2);
         
         regis=info.regis2;      
                 
         
         printf("\n\n\t\t PLEASE ENTER THE AMOUNT OF CUSTOMER YOU WANT TO ADD:");
         scanf("%d",&num);
         
         printf("\n\n\t\t\t  PLEASE ENTER THE CUSTOMER INFORMATION BELOW");    
            
           
        for(x=1;x<=num;x++)
        {                        
                             
         printf("\n\n\t\t\t       ENTER PATIENTS NUMBER %d DETAILS",x);   
             
         printf("\n\n\t\t\t  NAME: ");
         fflush(stdin);
         gets(info.Name);     
         
         printf("\n\n\t\t\t  ADDRESS: ");
         gets(info.address);
         
         printf("\n\n\t\t\t  NUMBER: ");
         gets(info.number);
         
         printf("\n\n\t\t\t  TREATMENT: ");
         gets(info.treatment);
         
         printf("\n\n\t\t\t  ALLERGIES: ");
         gets(info.allergies); 
         
         printf("\n\n\t\t\t  DATE OF BIRTH 12/12/12: "); 
         gets(info.dob);     
            
         printf("\n\n\t\t\t  DATE OF LAST APPOINTMENT 12/12/12: ");
         gets(info.app);
         
             
         system("cls");
         
         system("color 2");
         
         if (customer1==NULL)
                printf("\n\n\t\t\t  FILE WAS NOT FOUND ");
         else
             {
                                  
                                    
                regis++;                         
                
                fprintf(customer1,"%d %s %s %s %s %s %s %s\n",regis,info.Name,info.address,info.number,info.dob,info.treatment,info.allergies,info.app);
                
                                   
             }
             
             if(cust==NULL)
               printf("\n\n\t\t\t  FILE NOT FOUND");
           else
           {    
                   regis2++;                          
                    if (x==num)
                       fprintf(cust,"%d",regis2);
                       }      
           
            } 
           
           
           
           
           
         fclose(cust);              
         fclose(customer1);     
         
    }

    File 1
    1001 .................................
    1002.................................

    File 2
    1002

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Just an idea

    Wait...so what's the question?
    sudo rm -rf /

  4. #3
    hbk
    hbk is offline Learning Programmer
    Join Date
    Mar 2010
    Posts
    68
    Rep Power
    0

    Re: Just an idea

    how do i achieve the task.

  5. #4
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Just an idea

    Well, I'm assuming you know how to use fscanf, so you can just read the record number from there, and the open your file in append mode and the write pointer will go straight to the end.
    Code:
    FILE *last, *records;
    last = fopen("last.txt","r+");
    records = fopen("records.txt","a+");
    
    int lastrecord;
    fscanf(last,"&#37;d",&lastrecord);
    
    /* now you have the last record number,
    and can write directly into the file to make
    a new record */
    
    fclose(last);
    fclose(records);
    sudo rm -rf /

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. If I have an idea...
    By Goose001 in forum Community Projects
    Replies: 2
    Last Post: 12-12-2009, 05:27 AM
  2. Need an idea
    By Psynic in forum C# Programming
    Replies: 11
    Last Post: 09-28-2009, 01:55 PM
  3. What do you think of this idea?
    By NeximusF in forum C and C++
    Replies: 2
    Last Post: 08-16-2009, 07:35 PM
  4. an idea
    By Elliott in forum General Programming
    Replies: 3
    Last Post: 07-31-2008, 06:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts