ソースコード
源文件
1|
2|
3|#include <stdio.h>
4|#include <string.h>
5|#include <stdlib.h>
6|
7|#define FNAME "meibo.txt"
8|#define RECORDLEN 88
9|
10|int menu();
11|int myread();
12|int mywrite();
13|int myrewrite();
14|
15|char *format = "%-15s %-3d %-2 %-63s\n";
16|
17|int main(void)
18|{
19| int menuno;
20| while(1){
21| menuno = menu();
22| switch (menuno){
23| case 0:
24| break;
25| case 1:
26| mywrite();
27| break;
28| case 2:
29| myread();
30| break;
31| case 3:
32| myrewrite();
33| break;
34| default:
35| printf("不正です\n");
36| break;
37| }
38| if(!menuno){
39| break;
40| }
41| }
42| return 0;
43|}
44|
45|int menu()
46|{
47| char ret[8];
48|
49| while(1){
50| printf("*************************\n");
51| printf("1:データ書込み(新規•追加)\n");
52| printf("2:データ読み出し\n");
53| printf("3:データ修正\n");
54| printf("0:終了\n");
55| printf("*************************\n");
56| printf("選択-->");
57| scanf("%s", ret);
58| ret[1] = '\n';
59| if(ret[0] < '0' || ret[0] > '3') {
60| printf("番号が不正です\an>"keyword">return -1;
78| }
79| while(1){
80| printf("氏名--");
81| scanf("%s", name);
82| printf("年齢--");
83| scanf(90| if(fprintf(fp, format, name, age, sex, address) < 0){
91| perror("書込むエラーが発生しました");
92| break;
93| }
94| printf("さらに入力を続けますか(y/n):");
95| scanf("%s", buffer);
96| if(buffer[0] == return 0;
102|}
103|
104|
105|int myread()
106|pan>| perror("ファイルをオープンできません\n");
114| return -1;
115| }
116| printf("検索する氏名--");
117| scanf("%s", search);
118|
119| while(1) {
120| fseek(fp, RECORDLEN *s="string">"%d", &age);
126| fscanf(fp, "%s", sex);
127| fscanf(fp, "%s", address);
128| printf("氏名: %s\n", name);
129| printf("年齢: %d\n", age);
130(yesno[0] == 'y' || yesno[0] == 'Y'){
136| continue;
137| } else {
138| break;
139| }
140| }
141| }
142| printf("%d件が検索されました\n", finpan class="number">149| FILE *fp;
150| char buffer[8], shusei[16], yesno[8],
151| name[16], sex[4], address[64"修正するデータの氏名--");
160| scanf("%s", shusei);
161|
162| while(1){
163| fseek(fp, RECORDLEN * no++, SEEK_SET);
164| 171| fscanf(fp, "%s", address);
172| printf("氏名: %s\n", name);
173| printf("年齢: %d\n", age);
174| printf("性別: %s\n", sex);
175| printf(180| printf("氏名を修正いますか(Y/N):");
181| scanf("%s", yesno);
182| if(yesno[0] == 'y' || yesno[0] == 'Y') {
183| printf("氏名--== 'y' || yesno[0] == 'Y'){
189| printf("年齢--");
190| scanf("%s", buffer);
191| age = atoi(buffer);
192| }
193| printf("性別を修正しますか(Y/N):");
194| scanf("%s", yesno);
195| if(yesno[pan>| }
199| printf("住所を修正しますか(Y/N):");
200| scanf("%s", yesno);
201| if(yesno[0] == 'y' || yesno[0] == 'Y'){
202| prinber">210| if(find == 0){
211| printf("修正すべきデータはありませんでした\n");
212| }
213| fclose(fp);
214| return 0;
215|}
|