Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct db {
- char name[19];
- char date[10];
- char phone_number[13];
- char surname[19];
- } Zakaz;
- struct db_data {
- char actual;
- struct data;
- char new_line;
- };
- char getmenu();
- char find_menu();
- void print_all(struct db Zakaz, FILE *f, int size_of_str);
- void print_all(struct db Zakaz, FILE *f, int size_of_str){
- f=fopen("Zakaz.txt","r+");
- char ch;
- while(!feof(f)){
- // fscanf(f, " %19s, %10s, 13s, %21s\n", Zakaz.name, Zakaz.date, Zakaz.phone_number, Zakaz.surname);
- ch=fgetc(f);
- fscanf(f, "%19s, ", Zakaz[i].name);
- //====================================================================================================
- // 1. Zakaz.name -> Zakaz[i].name
- // 2. Zakaz[i].name -> &Zakaz[i].name
- // 3. если не вариант, то попробуй заюзать fgets() (http://www.cplusplus.com/reference/cstdio/fgets/)
- //====================================================================================================
- fscanf(f, "%10s, ", Zakaz.date);
- fscanf(f, "%13s, ", Zakaz.phone_number);
- fscanf(f, "%19s", Zakaz.surname);
- fscanf(f, "\n");
- if(ch!='^'){
- printf("%19s, ", Zakaz.name);
- printf("%10s, ", Zakaz.date);
- printf("%13s, ", Zakaz.phone_number);
- printf("%19s, ", Zakaz.surname);
- printf("\n");
- }
- else{
- fseek(f, size_of_str, SEEK_CUR);
- }
- }
- fclose(f);
- }
- #include <stdio.h>
- #include <string.h>
- #include "lab_6.h"
- int main(int argc, char *argv[])
- {
- struct Zakaz;
- FILE *f;
- system("color 6");
- if ((f=fopen("Zakaz.txt","r+"))==NULL){
- printf("Impossible to open the file. Creating a new file...\n\n");
- f=fopen("Zakaz.txt","w+");
- fclose(f);
- }
- 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)));
- int del=0;
- while(1){
- switch(getmenu()){
- case '1':print_all(Zakaz, f, size_of_str); break;
- case '2':add_to_db(Zakaz, f); break;
- case '3':find_in_db(Zakaz, f, del, size_of_str); break;
- case '4':del_from_db(Zakaz, f); break;
- case '5':return 0;
- }
- printf("\nPress any key to return to the menu\n\n");
- getch();
- system("cls");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement