本文實例為大家分享了C語言實現(xiàn)班級學生管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
下面是根據(jù)班級,這個人數(shù)較少的單位設計的學籍管理系統(tǒng),錄入時,要求班內(nèi)序號由1開始 按順序錄入,其中主要用到了 結(jié)構(gòu)體數(shù)組,文件處理,循環(huán)語句,選擇語句等方面的知識
在設計中遇到一個問題就是:不知道怎樣修改已經(jīng)保存在文件中的某一個指定學生的信息,后來在詢問學長之后才了解到 ,可以: 先把文件中的數(shù)據(jù)全部讀入結(jié)構(gòu)體數(shù)組中,再修改指定序號的數(shù)組元素,然后再用“wt”的方式寫進原文件,這樣就可以刪除文件里的原內(nèi)容,再寫進新內(nèi)容
下面是源代碼,在Dev-C++ 條件下進行編譯
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
|
#include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> int count1=0; int count2=0; int count3=0; void class_print(); void men1_student(); void men2_student(); void men3_student(); void men4_student(); void input_student(); void input_grade(); void input_reward(); void input_finance(); void report_finance(); void seek_student(); void seek_grade(); void seek_reward(); void change_student(); void change_grade(); void change_reward(); int now1_student(); int now2_student(); int now3_student(); struct date { int year; int month; int day; }; struct student { char number[2]; char name[10]; char sex[4]; char tel[15]; char id[20]; char study[10]; }; struct grade { char number[2]; char name[10]; char math[4]; char English[4]; char Cprogram[4]; char sumtest[4]; }; struct reward { char number[2]; char name[10]; struct date time ; char rewarding[80]; }; struct finance { char thing[20]; char type[8]; struct date time2; int i; }; struct student m_stu[50]; struct grade g_stu[50]; struct reward r_stu[50]; struct finance f_class; struct grade t_change; main() { int choice=-1; //一級菜單 while (choice!=0) { printf ( "\n" ); printf ( "\t\t\t\t\t\t**" ); class_print(); printf ( "**\n" ); printf ( "\t\t\t\t\t\t****************************\n" ); printf ( "\t\t\t\t\t\t** 班級學生學籍管理系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 1.戶籍管理系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 2.成績管理系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 3.獎懲管理系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 4.財務管理系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 0.退 出 **\n" ); printf ( "\t\t\t\t\t\t請選擇" ); scanf ( "%d" ,&choice); switch (choice) { case 1: men1_student(); break ; case 2: men2_student(); break ; case 3: men3_student(); break ; case 4: men4_student(); break ; case 0: printf ( "返回上一級" ); break ; default : break ; } } } void men1_student() //二級菜單(學生戶籍管理) { int choice=-1; while (choice!=0) { printf ( "\n" ); printf ( "\t\t\t\t\t\t****************************\n" ); printf ( "\t\t\t\t\t\t**" ); class_print(); printf ( "**\n" ); printf ( "\t\t\t\t\t\t** 班級學生戶籍信息管理 **\n" ); printf ( "\t\t\t\t\t\t** 戶籍信息已錄入人數(shù):" );now1_student(); printf ( " **\n" ); printf ( "\t\t\t\t\t\t** 1.戶籍錄入系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 2.戶籍修改系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 3.戶籍查詢系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 0.返 回 **\n" ); printf ( "\t\t\t\t\t\t請選擇" ); scanf ( "%d" ,&choice); switch (choice) { case 1: input_student(); break ; case 2: change_student(); break ; case 3: seek_student(); break ; case 0: printf ( "返回上一級" ); break ; default : break ; } getch(); } } void input_student() // 戶籍錄入函數(shù) 錄入信息保存至D盤根目錄下information1.txt文件下 { int j; printf ( "學生戶籍信息錄入" ); printf ( "\n班內(nèi)序號: " ); scanf ( "%s" ,&m_stu[count1].number); printf ( "\n姓名: " ); gets (m_stu[count1].name); gets (m_stu[count1].name); printf ( "\n性別: " ); scanf ( "%s" ,&m_stu[count1].sex); printf ( "\n電話號碼: " ); scanf ( "%s" ,&m_stu[count1].tel); printf ( "\n身份證號: " ); scanf ( "%s" ,&m_stu[count1].id); printf ( "\n學號: " ); scanf ( "%s" ,&m_stu[count1].study); printf ( "是否保存該學生信息?1-保存 2-放棄" ); scanf ( "%d" ,&j); if (j==1) { FILE *info; //保存至本地文件 info= fopen ( "d:\\information1.txt" , "at+" ); fwrite (&m_stu[count1], sizeof ( struct student),1,info); fclose (info); printf ( "信息已保存至D:\\information1.tex 文件下,按任意鍵繼續(xù)" ); count1++; } else printf ( "放棄保存,按任意鍵繼續(xù)" ); } void seek_student() //查詢戶籍信息函數(shù) { FILE *info; info= fopen ( "d:\\information1.txt" , "rt" ); int i; printf ( "請輸入該學生班內(nèi)序號" ); scanf ( "%d" ,&i); if (i<1||i>50) printf ( "抱歉,該學生信息不存在" ); else { rewind (info); fseek (info, sizeof ( struct student)*(i-1),0); fread (&m_stu[i-1], sizeof ( struct student),1,info); printf ( "\n\n序號 姓名 性別 電話號碼\t 身份證號\t\t學號\t" ); printf ( "\n\n%d %s %s %s %s %s" ,i,m_stu[i-1].name,m_stu[i-1].sex,m_stu[i-1].tel,m_stu[i-1].id,m_stu[i-1].study); } } void change_student() //修改戶籍信息 { int i=0,j,k,f; char h[100000]; FILE *info; info= fopen ( "d:\\information1.txt" , "rt" ); printf ( "\n\t請輸入要修改戶籍信息的學生班內(nèi)序號" ); scanf ( "%d" ,&j); if (j<1||j>50) printf ( "抱歉,該學生信息不存在" ); else { rewind (info); while ( fgets (h, sizeof ( struct student),info)!=NULL) { fseek (info, sizeof ( struct student)*i,0); fread (&m_stu[i], sizeof ( struct student),1,info); i++; } } fclose (info); printf ( "\n該學生目前戶籍信息為\n:" ); printf ( "\n\n序號 姓名 性別 電話號碼\t 身份證號\t\t學號\t" ); printf ( "\n\n%d %s %s %s %s %s" ,j,m_stu[j-1].name,m_stu[j-1].sex,m_stu[j-1].tel,m_stu[j-1].id,m_stu[j-1].study); printf ( "確定修改此學生信息?1- 修改 2- 返回" ); scanf ( "%d" ,&k); if (k==1) { printf ( "\n姓名: " ); gets (m_stu[j-1].name); gets (m_stu[j-1].name); printf ( "\n性別: " ); scanf ( "%s" ,&m_stu[j-1].sex); printf ( "\n電話號碼: " ); scanf ( "%s" ,&m_stu[j-1].tel); printf ( "\n身份證號: " ); scanf ( "%s" ,&m_stu[j-1].id); printf ( "\n學號: " ); scanf ( "%s" ,&m_stu[j-1].study); } else return ; info= fopen ( "d:\\information1.txt" , "wt" ); for (f=0;f<i;f++) { fseek (info, sizeof ( struct student)*f,0); fwrite (&m_stu[f], sizeof ( struct student),1,info); } fclose (info); printf ( "修改成功!" ); } void men2_student() //二級菜單(學生成績管理) { int choice=-1; while (choice!=0) { printf ( "\n\t\t\t\t\t\t****************************\n" ); printf ( "\t\t\t\t\t\t**" ); class_print(); printf ( "**\n" ); printf ( "\t\t\t\t\t\t** 班級學生成績信息管理 **\n" ); printf ( "\t\t\t\t\t\t** 成績信息已錄入人數(shù):" );now2_student(); printf ( " **\n" ); printf ( "\t\t\t\t\t\t** 1.成績錄入系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 2.成績修改系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 3.成績查詢系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 4.綜測排名系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 0.返 回 **\n" ); printf ( "\t\t\t\t\t\t請選擇" ); scanf ( "%d" ,&choice); switch (choice) { case 1:input_grade(); break ; case 2:change_grade(); break ; case 3:seek_grade(); break ; case 4: printf ( "功能正在研發(fā)中,敬請期待..." ); break ; default : break ; } getch(); } } void input_grade() // 成績錄入函數(shù) ,錄入信息保存至 D盤根目錄下information2.txt文件下 { int j; printf ( "學生成績信息錄入" ); printf ( "\n班內(nèi)序號" ); scanf ( "%s" ,&g_stu[count2].number); printf ( "\n姓名: " ); gets (g_stu[count2].name); gets (g_stu[count2].name); printf ( "\n高數(shù): " ); scanf ( "%s" ,&g_stu[count2].math); printf ( "\n英語:" ); scanf ( "%s" ,&g_stu[count2].English); printf ( "\nC語言:" ); scanf ( "%s" ,&g_stu[count2].Cprogram); printf ( "\n綜測:" ); scanf ( "%s" ,&g_stu[count2].sumtest); printf ( "是否保存該學生信息?1-保存 2-放棄" ); scanf ( "%d" ,&j); if (j==1) { FILE *info2; //保存至本地文件 info2= fopen ( "d:\\information2.txt" , "at+" ); fwrite (&g_stu[count2], sizeof ( struct grade),1,info2); fclose (info2); printf ( "信息已保存至D:\\information.tex2 文件下,按任意鍵繼續(xù)" ); count2++; } else printf ( "放棄保存,按任意鍵繼續(xù)" ); } void seek_grade() //查詢成績信息函數(shù) { FILE *info2; info2= fopen ( "d:\\information2.txt" , "rt" ); int i; printf ( "\n\t請輸入該學生班內(nèi)序號" ); scanf ( "%d" ,&i); if (i<1||i>50) printf ( "\n抱歉,該學生信息不存在" ); else { rewind (info2); fseek (info2, sizeof ( struct grade)*(i-1),0); fread (&g_stu[i-1], sizeof ( struct grade),1,info2); printf ( "\n\n序號 姓名 高數(shù) 英語 C語言 綜測" ); printf ( "\n\n%d %s %s %s %s %s" ,i,g_stu[i-1].name,g_stu[i-1].math,g_stu[i-1].English,g_stu[i-1].Cprogram,g_stu[i-1].sumtest); } } void change_grade() //修改成績信息 { int i=0,j,k,f; char h[100000]; FILE *info; info= fopen ( "d:\\information2.txt" , "rt" ); printf ( "\n\t請輸入要修改成績信息的學生班內(nèi)序號" ); scanf ( "%d" ,&j); if (j<1||j>50) printf ( "\n抱歉,該學生信息不存在" ); else { rewind (info); while ( fgets (h, sizeof ( struct grade),info)!=NULL) { fseek (info, sizeof ( struct grade)*i,0); fread (&g_stu[i], sizeof ( struct grade),1,info); i++; } } fclose (info); printf ( "\n該學生目前成績信息為\n:" ); printf ( "\n\n序號 姓名 高數(shù) 英語 C語言 綜測" ); printf ( "\n\n%d %s %s %s %s %s" ,j,g_stu[j-1].name,g_stu[j-1].math,g_stu[j-1].English,g_stu[j-1].Cprogram,g_stu[j-1].sumtest); printf ( "\n\t確定修改此學生信息?1- 修改 2- 返回" ); scanf ( "%d" ,&k); if (k==1) { printf ( "\n姓名: " ); gets (g_stu[j-1].name); gets (g_stu[j-1].name); printf ( "\n高數(shù): " ); scanf ( "%s" ,&g_stu[j-1].math); printf ( "\n英語: " ); scanf ( "%s" ,&g_stu[j-1].English); printf ( "\nC語言: " ); scanf ( "%s" ,&g_stu[j-1].Cprogram); printf ( "\n綜測: " ); scanf ( "%s" ,&g_stu[j-1].sumtest); } else return ; info= fopen ( "d:\\information2.txt" , "wt" ); if (info==NULL) { printf ( "不能打開此文件,按任意鍵繼續(xù)" ); getch(); } for (f=0;f<i;f++) { fseek (info, sizeof ( struct grade)*f,0); fwrite (&g_stu[f], sizeof ( struct grade),1,info); } fclose (info); printf ( "修改成功!" ); } void men3_student() //二級菜單(學生獎懲管理) { int choice=-1; while (choice!=0) { printf ( "\n" ); printf ( "\t\t\t\t\t\t****************************\n" ); printf ( "\t\t\t\t\t\t**" ); class_print(); printf ( "**\n" ); printf ( "\t\t\t\t\t\t** 班級學生獎懲信息管理 **\n" ); printf ( "\t\t\t\t\t\t** 獎懲信息已錄入人數(shù):" );now3_student(); printf ( " **\n" ); printf ( "\t\t\t\t\t\t** 1.獎懲錄入系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 2.獎懲修改系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 3.獎懲查詢系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 0.返 回 **\n" ); printf ( "\t\t\t\t請選擇" ); scanf ( "%d" ,&choice); switch (choice) { case 1: input_reward(); break ; case 2: change_reward(); break ; case 3: seek_reward(); break ; case 0: printf ( "返回上一級" ); break ; default : break ; } getch(); } } void input_reward() // 獎懲錄入函數(shù) 錄入信息保存至D盤根目錄下information3.txt文件下 { int j; printf ( "學生獎懲信息錄入" ); printf ( "\n班內(nèi)序號: " ); scanf ( "%s" ,&r_stu[count3].number); printf ( "\n姓名: " ); gets (r_stu[count3].name); gets (r_stu[count3].name); printf ( "\n獎懲時間: " ); scanf ( "%d.%d.%d" ,&r_stu[count3]. time .year,&r_stu[count3]. time .month,&r_stu[count3]. time .day); printf ( "\n具體事件: " ); gets (r_stu[count3].rewarding); gets (r_stu[count3].rewarding); printf ( "\n是否保存該學生信息?1-保存 2-放棄" ); scanf ( "%d" ,&j); if (j==1) { FILE *info; //保存至本地文件 info= fopen ( "d:\\information3.txt" , "at+" ); fwrite (&r_stu[count3], sizeof ( struct reward),1,info); fclose (info); printf ( "\n信息已保存至D:\\information3.tex 文件下,按任意鍵繼續(xù)" ); count3++; } else printf ( "放棄保存,按任意鍵繼續(xù)" ); } void seek_reward() //查詢獎懲信息函數(shù) 根據(jù)學生班級序號 { FILE *info; info= fopen ( "d:\\information3.txt" , "rt" ); int i; printf ( "\n\t請輸入該學生班內(nèi)序號" ); scanf ( "%d" ,&i); if (i<1||i>50) printf ( "\n抱歉,該學生信息不存在" ); else { rewind (info); fseek (info, sizeof ( struct reward)*(i-1),0); fread (&r_stu[i-1], sizeof ( struct reward),1,info); printf ( "\n\n序號 姓名 獎懲時間 具體事件\t\t" ); printf ( "\n\n%d %s %d.%d.%d %s " ,i,r_stu[i-1].name,r_stu[i-1]. time .year, r_stu[i-1]. time .month, r_stu[i-1]. time .day, r_stu[i-1].rewarding); } } void change_reward() //修改獎懲信息 { int i=0,j,k,f; char h[100000]; FILE *info; info= fopen ( "d:\\information3.txt" , "rt" ); printf ( "\n\t請輸入要修改獎懲信息的學生班內(nèi)序號" ); scanf ( "%d" ,&j); if (j<1||j>50) printf ( "\n抱歉,該學生信息不存在" ); else { rewind (info); while ( fgets (h, sizeof ( struct reward),info)!=NULL) { fseek (info, sizeof ( struct reward)*i,0); fread (&r_stu[i], sizeof ( struct reward),1,info); i++; } } fclose (info); printf ( "\n該學生目前獎懲信息為\n:" ); printf ( "\n\n序號 姓名 獎懲時間 具體事件" ); printf ( "\n\n%d %s %d.%d.%d %s " ,j,r_stu[j-1].name,r_stu[j-1]. time .year, r_stu[j-1]. time .month, r_stu[j-1]. time .day ,r_stu[j-1].rewarding); printf ( "\n\t確定修改此學生信息?1- 修改 2- 返回" ); scanf ( "%d" ,&k); if (k==1) { printf ( "\n姓名: " ); gets (r_stu[j-1].name); gets (r_stu[j-1].name); printf ( "\n獎懲時間: " ); scanf ( "%d.%d.%d" ,&r_stu[j-1]. time .year,&r_stu[j-1]. time .month,&r_stu[j-1]. time .day); printf ( "\n具體事件: " ); scanf ( "%s" ,&r_stu[j-1].rewarding); } else return ; info= fopen ( "d:\\information3.txt" , "wt" ); for (f=0;f<i;f++) { fseek (info, sizeof ( struct reward)*f,0); fwrite (&r_stu[f], sizeof ( struct reward),1,info); } fclose (info); printf ( "修改成功!" ); } int now1_student() //錄入戶籍信息學生數(shù)目 在菜單中 顯示 已經(jīng)錄入學生人數(shù) { int i=1; char j[100000]; FILE *info; info= fopen ( "D:\\information1.txt" , "rt" ); rewind (info); while ( fgets (j, sizeof ( struct student),info)!=NULL) { fseek (info, sizeof ( struct student)*i,0); i++; } fclose (info); printf ( "%d" ,i-1); } int now2_student() //錄入成績信息學生數(shù)目 在菜單中 顯示 已經(jīng)錄入學生人數(shù) { int i=1; char j[100000]; FILE *info; info= fopen ( "D:\\information2.txt" , "rt" ); rewind (info); while ( fgets (j, sizeof ( struct grade),info)!=NULL) { fseek (info, sizeof ( struct grade)*i,0); i++; } fclose (info); printf ( "%d" ,i-1); } int now3_student() //錄入獎懲信息學生數(shù)目 在菜單中 顯示 已經(jīng)錄入學生人數(shù) { int i=1; char j[100000]; FILE *info; info= fopen ( "D:\\information3.txt" , "rt" ); rewind (info); while ( fgets (j, sizeof ( struct reward),info)!=NULL) { fseek (info, sizeof ( struct reward)*i,0); i++; } fclose (info); printf ( "%d" ,i-1); } void class_print() // 錄入專業(yè)班級信息,并保存至D盤根目錄下information0.txt文件下 { char major[20],class_number[4]; FILE *info; info= fopen ( "d:\\information0.txt" , "rt" ); if (info==NULL) { info= fopen ( "d:\\information0.txt" , "wt" ); printf ( "\n請輸入專業(yè) :" ); scanf ( "%s" ,&major); printf ( "\n請輸入班級 :" ); scanf ( "%s" ,&class_number); fwrite (major, sizeof (major),1,info); fwrite (class_number, sizeof (class_number),1,info); printf ( "\n\t已保存專業(yè)班級信息!" ); fclose (info); info= fopen ( "d:\\information0.txt" , "rt" ); fread (&major, sizeof (major),1,info); fread (&class_number, sizeof (class_number),1,info); printf ( "%s" ,major); printf ( "%s班" ,class_number); } else { fread (&major, sizeof (major),1,info); fread (&class_number, sizeof (class_number),1,info); printf ( "%s" ,major); printf ( "%s班" ,class_number); fclose (info); } } void men4_student() //二級菜單(班級財務管理) { int choice=-1; while (choice!=0) { printf ( "\n" ); printf ( "\t\t\t\t\t\t****************************\n" ); printf ( "\t\t\t\t\t********財務信息不可修改,請謹慎錄入!******\n" ); printf ( "\t\t\t\t\t\t** 班級學生財務信息管理 **\n" ); printf ( "\t\t\t\t\t\t** 1.財務錄入系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 2.財務報表系統(tǒng) **\n" ); printf ( "\t\t\t\t\t\t** 0.返 回 **\n" ); printf ( "\t\t\t\t\t\t請選擇" ); scanf ( "%d" ,&choice); switch (choice) { case 1: input_finance(); break ; case 2: report_finance(); break ; case 3: case 0: printf ( "返回上一級" ); break ; default : break ; } getch(); } } void input_finance() // 財務錄入函數(shù) ,錄入后信息保存到D盤根目錄下 information4.txt文件中 { int j; printf ( "班級財務信息錄入" ); printf ( "\n收支時間: " ); scanf ( "%d.%d.%d" ,&f_class.time2.year,&f_class.time2.month,&f_class.time2.day ); printf ( "\n具體事件: " ); gets (f_class.thing); gets (f_class.thing); printf ( "\n財務類型(收入或開支): " ); scanf ( "%s" ,&f_class.type); printf ( "\n流動金額(收入為正開支為負): " ); scanf ( "%d" ,&f_class.i); printf ( "\n是否保存該財務信息?1-保存 2-放棄" ); scanf ( "%d" ,&j); if (j==1) { FILE *info; //保存至本地文件 info= fopen ( "d:\\information4.txt" , "at+" ); fwrite (&f_class, sizeof ( struct finance),1,info); fclose (info); printf ( "\n信息已保存至D:\\information4.txt 文件下,按任意鍵繼續(xù)" ); } else printf ( "放棄保存,按任意鍵繼續(xù)" ); } void report_finance() // 財務信息報表 { char h[100000]; int sum=0,i=0; printf ( "\n收支時間 具體事件\t財務類型 流動金額\n" ); FILE *info; info= fopen ( "d:\\information4.txt" , "rt" ); while ( fgets (h, sizeof ( struct finance),info)!=NULL) { fseek (info, sizeof ( struct finance)*i,0); fread (&f_class, sizeof ( struct finance),1,info);i++; printf ( "\n%d.%d.%d %s %s %d\n" ,f_class.time2.year, f_class.time2.month, f_class.time2.day, f_class.thing,f_class.type,f_class.i); sum=sum+f_class.i ; } printf ( "\n\t\t班費余額:%d元" ,sum); } |
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/wintershii/article/details/78946171