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
//##########################################
//
//					define
//
//##########################################
FILE		*file_pointer;
char 		File_Name[] 	= "";
Load_Type 	load_data;
int 		line_num 		= 0;
int 		total_line_num	= 0;


void main()
{
//##########################################
//
//					save
//
//##########################################
	int max_line_size = 9999999;
	char line_buff[max_line_size];

	sprintf(File_Name,"record_%d.dat",0);

	if ((file_pointer = fopen(File_Name, "w")) != NULL)
	{
		fprintf(file_pointer,"%15.6f, %15.6f, %15.6f, %6.3f, %6.3f, %6.3f\n"
				, data.Position_X
				, data.Position_Y
				, data.Position_Z
				, data.Roll
				, data.Pitch
				, data.Yaw);
		printf("%15.6f, %15.6f, %15.6f, %6.3f, %6.3f, %6.3f\n"
				, data.Position_X
				, data.Position_Y
				, data.Position_Z
				, data.Roll
				, data.Pitch
				, data.Yaw);

		fclose(file_pointer);
	}

//##########################################
//
//					load
//
//##########################################

	sprintf(File_Name,"record_%d.dat",0);

	if ((file_pointer = fopen(File_Name, "r")) != NULL)
	{
		while(fgets(line_buff,max_line_size, file_pointer) != NULL)
		{
			total_line_num++;
			if (line_buff[0] == '\0' || line_buff[0] == EOF) total_line_num--;
		}
		rewind(file_pointer);

		if (feof(file_pointer) == 0)
		{
			memset(&load_data,0,sizeof(load_data));
			fscanf(file_pointer,"%lf",&load_data.Position_X);
			fscanf(file_pointer,", %lf",&load_data.Position_Y);
			fscanf(file_pointer,", %lf",&load_data.Position_Z);
			fscanf(file_pointer,", %lf",&load_data.Roll);
			fscanf(file_pointer,", %lf",&load_data.Pitch);
			fscanf(file_pointer,", %lf",&load_data.Yaw);
			line_num++;

			printf("%5d,%5d %15.6f, %15.6f, %15.6f, %6.3f, %6.3f, %6.3f\n"
					,total_line_num
					,line_num
					,load_data.Position_X
					,load_data.Position_Y
					,load_data.Position_Z
					,load_data.Roll
					,load_data.Pitch
					,load_data.Yaw);
		}
		else if (feof(file_pointer) != 0)
		{
			//fseek(file_pointer,0,SEEK_SET);
			rewind(file_pointer);
			line_num = 0;
		}

	fclose(file_pointer);
	}
}









'C언어' 카테고리의 다른 글

c언어 파일 저장 및 로드 예제 2  (0) 2013.11.27
c언어 파일 관련 함수  (0) 2013.11.27
c++ 공부 요점정리 16  (0) 2013.11.23
c++ 공부 요점정리 15  (0) 2013.11.23
c++ 공부 요점정리 14  (0) 2013.11.23
Posted by 뮹실이

최근에 달린 댓글

05-28 18:22
Yesterday
Today
Total