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
|
#include <stdio.h>
#include <stdlib.h>
#define MAX_NAME_LEN 20
typedef struct _Student Student;
struct _Student{
char name[MAX_NAME_LEN+1];
int age;
int num;
};
void store_students();
void search_student();
int main(){
store_students();
search_student();
return 0;
}
void store_students(){
Student base[4]={
{"홍길동",20,3},{"감감찬",30,4},{"김유신",70,1},{"이순신",35,2}};
fwrite(base,sizeof(Student),4,fp);
fclose(fp);
}
void search_student()
{
fseek(fp,0,SEEK_END);
int cnt=ftell(fp)/sizeof(Student);
rewind(fp);
printf("cnt=%d\n",cnt);
int nth=0;
printf("원하는 순번(1~%d):",cnt);
scanf("%d",&nth);
if((nth<=0)||(nth>cnt))
{
printf("cnt=%d\n",cnt);
printf("???:error");
return;
}
fseek(fp,(nth-1)*sizeof(Student),SEEK_SET);
Student student;
fread(&student,sizeof(Student),1,fp);
fclose(fp);
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
'딥러닝 기반 영상인식 개발 전문가 과정 > 리눅스' 카테고리의 다른 글
5월30일 시간과 날짜 연산 (0) | 2019.05.30 |
---|---|
5월30일 파일과디렉토리, 특수 목적 파일 연산 (0) | 2019.05.30 |
5월29일 리눅스 2 형기반입출력, 줄단위, 버퍼기반, 읽기/쓰기 오프셋 재배치, 디렉토리 생성과 삭제 (0) | 2019.05.29 |
5월29일 리눅스 1 #dup삭제#Seeker삭제#디스크립터삭제#오프셋삭제#FILE삭제#스트림삭제# (0) | 2019.05.29 |
5월28일 유틸리티 루틴, 저수준 입출력 루틴 (0) | 2019.05.28 |