. , : , , . , .
:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
const int L=30;
typedef struct {char name[30]; int gr;float oklad;} MAN; // MAN
FILE *aa, *temp; // temp
void main() //
{int a;
void VIEW(), APP(), NEWFILE(), EDITF(); //
clrscr(); //
do //
{ printf(" \n MAIN MENU ");
printf("\n 0. NEW FILE");
printf("\n 1. VIEW FILE");
printf("\n 2. APPEND FILE);
printf("\n 3. EDIT FILE");
printf("\n 4. EXIT");
printf("\n\n\n Input punkt of main menu: ");
scanf("%d", &a); //
switch (a)
{case 0: { NEWFILE(); break;} //
case 1: { VIEW(); break;}
case 2: { APP(); break;}
case 3: { EDITF(); break;}
case 4: { printf(" Good Bye! "); break;}
default: printf("ERROR!!!"); break;
}
} while(a!=4);
}
void LINE() //
{ for (i=1;i<35;i++) printf("_"); printf("\n"); }
void VIEW() //, OKLAD.txt
{ int count=0,i;
MAN buf; // MAN
aa=fopen("OKLAD.txt","r"); // OKLAD.txt
LINE(); printf("\nN | FIO | God | OkJIag(py6)\n\n"); LINE(); //
while(!feof(aa)) //
{
fscanf(aa,"%s%d%f", &buf.name, &buf.gr, &buf.oklad); //
count++;
printf("\n%d.| %-10s| %5d |%10.2f\n", count, buf.name, buf.gr, buf.oklad); //
}
LINE();
fclose(aa); // OKLAD.txt
}
void APP() //, OKLAD.txt
{int n,i;
MAN buf;
aa=fopen("OKLAD.txt","a"); // OKLAD.txt
printf("CKOJIbKO 3anuceu' BBoguTb? "); scanf("%d", &n);
for(i=1;i<=n;i++)
{printf("BBeguTe qpaMuJIuI0:"); scanf("%s", &buf.name);
printf("BBeguTe rog po}I{geHu9:"); scanf("%d", &buf.gr);
printf("BBeguTe CyMMy OKJIaga:"); scanf("%f", &buf.oklad);
fprintf(aa, "\n%s %d %f", buf.name, buf.gr, buf.oklad); //
}
fclose(aa); // OKLAD.txt
}
void NEWFILE() //, OKLAD.txt
{int n,i;
MAN buf;
aa=fopen("OKLAD.txt","w"); // OKLAD.txt
printf("CKOJIbKO 3anuceu' BBoguTb? "); scanf("%d", &n);
|
|
for(i=1;i<=n;i++)
{printf("BBeguTe qpaMuJIuI0:"); scanf("%s", &buf.name);
printf("BBeguTe rog po}I{geHu9:"); scanf("%d", &buf.gr);
printf("BBeguTe CyMMy OKJIaga:"); scanf("%f", &buf.oklad);
fprintf(aa, "\n%s %d %f", buf.name,buf.gr,buf.oklad); //
}
fclose(aa); // OKLAD.txt
}
void EDITF() //, OKLAD.txt
{aa=fopen("OKLAD.txt", "r"); // OKLAD.txt
temp=fopen("temp.txt", "w"); // temp.txt
int K,i;
MAN buf;
char str[30];
printf("BBeguTe HoMep pegakTupyeMou' 3anucu:"); scanf("%d", &K);
for(i=1;i<K;i++) // (-1) OKLAD.txt temp.txt
{fscanf(aa,"%s%d%f", &buf.name,&buf.gr, &buf.oklad); // OKLAD.txt
fprintf(temp, "\n%s %d %f", buf.name,buf.gr,buf.oklad); // temp.txt
}
// - OKLAD.txt
fscanf(aa,"%s%d%f", &buf.name,&buf.gr, &buf.oklad);
printf("\n\n%30s %5d %10.2f\n", buf.name,buf.gr,buf.oklad);
fflush(stdin); //
printf("BBeguTe qpaMuJIuI0:"); gets(str);
if(strlen(str) > 1) strcpy(buf.name, str); // ,
printf("BBeguTe rog po}I{geHu9:"); gets(str);
if(strlen(str) > 1) buf.gr=atoi(str); // ,
printf("BBeguTe CyMMy OKJIaga:"); gets(str);
if(strlen(str) > 1) buf.oklad=atof(str); // ,
fprintf(temp, "\n%s %d %f", buf.name,buf.gr,buf.oklad);
// OKLAD.txt temp.txt
while(!feof(aa))
{fscanf(aa,"%s%d%f", &buf.name,&buf.gr, &buf.oklad);
fprintf(temp, "\n%s %d %f", buf.name,buf.gr,buf.oklad);
}
fclose(aa); fclose(temp); //
aa=fopen("OKLAD.txt", "w"); // OKLAD. txt
temp=fopen("temp.txt", "r"); // temp.txt
// temp.txt OKLAD.txt
while(!feof(temp))
{fscanf(temp,"%s%d%f", &buf.name,&buf.gr, &buf.oklad);
fprintf(aa, "\n%30s%5d%10.2f", buf.name,buf.gr,buf.oklad);
}
fclose(temp); fclose(aa); //
}
1. . :
- ;
- , .