include stdio include stdlib include locale void create void FILE int

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
void create(void){
FILE *p;
int a, s;
if((p=fopen("test.dat","wb"))==NULL){
puts("Íå óäàëîñü îòêðûòü ôàèë");
return;
}
system("cls");
puts("Ââåäèòå êîëè÷åñòâî öèôð");
scanf("%d", &a);
for(int i=0; i<a;i++){
scanf("%d", &s);
fwrite(&s,sizeof(int),1,p);
}
fclose(p);
system("PAUSE");
return;
}
void show(void){
FILE *p;
int a;
if((p=fopen("test.dat","rb"))==NULL){
puts("Íå óäàëîñü îòêðûòü ôàèë");
system("PAUSE");
return;
}
system("cls");
while(fread(&a,sizeof(int),1,p)){
printf("%d ", a);
}
fclose(p);
system("PAUSE");
return;
}
int main(void){
char g;
setlocale(LC_CTYPE,"Russian");
do{
system("cls");
puts("1. Ñîçäàòü ôàèë");
puts("2. Âûâåñòè ñîäåðæèìîå");
puts("3. Âûõîä");
g=getchar();
switch (g){
case '1':create();break;
case '2':show();break;
}
}while(g!='3');
return 0;
}