Advertisement
Mlack

Untitled

Apr 26th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. struct db {
  2.     char name[19];
  3.     char date[10];
  4.     char phone_number[13];
  5.     char surname[19];
  6.     } Zakaz;
  7.    
  8. struct db_data {
  9.     char actual;
  10.     struct data;
  11.     char new_line;
  12. };
  13.    
  14. char getmenu();
  15. char find_menu();
  16. void print_all(struct db Zakaz, FILE *f, int size_of_str);
  17.  
  18. void print_all(struct db Zakaz, FILE *f, int size_of_str){
  19.     f=fopen("Zakaz.txt","r+");
  20.     char ch;
  21.     while(!feof(f)){
  22.         //  fscanf(f, " %19s, %10s, 13s, %21s\n", Zakaz.name, Zakaz.date, Zakaz.phone_number, Zakaz.surname);
  23.         ch=fgetc(f);
  24.         fscanf(f, "%19s, ", Zakaz[i].name);
  25. //====================================================================================================
  26. // 1. Zakaz.name -> Zakaz[i].name
  27. // 2. Zakaz[i].name -> &Zakaz[i].name
  28. // 3. если не вариант, то попробуй заюзать fgets() (http://www.cplusplus.com/reference/cstdio/fgets/)
  29. //====================================================================================================
  30.         fscanf(f, "%10s, ", Zakaz.date);
  31.         fscanf(f, "%13s, ", Zakaz.phone_number);
  32.         fscanf(f, "%19s", Zakaz.surname);
  33.         fscanf(f, "\n");
  34.         if(ch!='^'){
  35.             printf("%19s, ", Zakaz.name);
  36.             printf("%10s, ", Zakaz.date);
  37.             printf("%13s, ", Zakaz.phone_number);
  38.             printf("%19s, ", Zakaz.surname);
  39.             printf("\n");          
  40.         }
  41.         else{
  42.             fseek(f, size_of_str, SEEK_CUR);
  43.         }
  44.     }
  45.     fclose(f);
  46. }
  47.  
  48. #include <stdio.h>
  49. #include <string.h>
  50. #include "lab_6.h"
  51.  
  52. int main(int argc, char *argv[])
  53. {
  54.     struct Zakaz;
  55.     FILE *f;
  56.    
  57.     system("color 6");
  58.     if ((f=fopen("Zakaz.txt","r+"))==NULL){
  59.         printf("Impossible to open the file. Creating a new file...\n\n");
  60.     f=fopen("Zakaz.txt","w+");
  61.     fclose(f);
  62.     }
  63.     int size_of_str=(9+(sizeof(Zakaz.name)/sizeof(char))+(sizeof(Zakaz.date)/sizeof(char))+(sizeof(Zakaz.name)/sizeof(char))+(sizeof(Zakaz.phone_number)/sizeof(char))+(sizeof(Zakaz.surname)/sizeof(char)));
  64.     int del=0;
  65.     while(1){
  66.     switch(getmenu()){
  67.     case '1':print_all(Zakaz, f, size_of_str); break;
  68.     case '2':add_to_db(Zakaz, f); break;
  69.     case '3':find_in_db(Zakaz, f, del, size_of_str); break;
  70.     case '4':del_from_db(Zakaz, f); break;
  71.     case '5':return 0;
  72.     }
  73.    
  74.     printf("\nPress any key to return to the menu\n\n");
  75.     getch();
  76.     system("cls");
  77.     }
  78.    
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement