Code that stores and retrieves.

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Mpiangu Mpiangu is offline Offline Apr 12th, 2007, 4:45 am |
0
hi every body try out this code it can store your info and then retriaeve it ant any time you wish.
They are two codes each wrote separatly so first write the outputting code and run it.
Then write the inputting code and also run it
have fun:lol:
Quick reply to this message  
C Syntax
  1. //code for out putting on the file private.dat.
  2.  
  3. #include<iostream.h>
  4.  
  5. #include<fstream.h>
  6.  
  7. #include<stdlib.h>
  8.  
  9. void main()
  10.  
  11. {
  12.  
  13. ofstream my_record("private.dat",ios::out);
  14.  
  15. if(!my_record)
  16.  
  17. {
  18.  
  19. cerr<<"the fail can not be created"<<endl;
  20.  
  21. exit(1);
  22.  
  23. }
  24.  
  25. int age;
  26.  
  27. char name[10];
  28.  
  29. int registration;
  30.  
  31. while(cin>>age>>name>>registration)
  32.  
  33. {
  34.  
  35. my_record<<age<<' '<<name<<' '<<registration<<endl;
  36.  
  37. cout<<"---"<<endl;
  38.  
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. //code for in putting on the file private.dat.
  48.  
  49. #include<iostream.h>
  50.  
  51. #include<fstream.h>
  52.  
  53. #include<stdlib.h>
  54.  
  55. void display(int,const char*const,int);
  56.  
  57. void main()
  58.  
  59. {
  60.  
  61. ifstream my_record("private.dat",ios::in);
  62.  
  63. if(!my_record)
  64.  
  65. {
  66.  
  67. cerr<<"the fail can not be found"<<endl;
  68.  
  69. exit(1);
  70.  
  71. }
  72.  
  73. int age;
  74.  
  75. char name[10];
  76.  
  77. int registration;
  78.  
  79. cout<<"AGE\t NAME \tREGESTRATION"<<endl;
  80.  
  81. while(my_recod>>age>>name>>registration)
  82.  
  83. diplay(age,name,registration);
  84.  
  85. }
  86.  
  87. void display(int d,const char*const t, int y)
  88.  
  89. {
  90.  
  91. cout<<d<<'\t'<<'\t'<<t<<'\t'<<'t'<<y<<endl;
  92.  
  93. }
0
Mpiangu Mpiangu is offline Offline | Apr 12th, 2007
exelent
 
 

Message:


Similar Threads
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC