Read values from file

So i have this .dat file:
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
############################################
# fonts.dat                                #
# stores the proportional values for fonts #
############################################

# amount of fonts to expect:
[TOTAL_FONTS]
1

#
# 1st font...  GTA HEADER
#

# this font id:
[FONT_ID]
0

# proportional values:
[PROP]
15   9  17  27  20  34  23  12	  #	0    ! " £ $ % & '
12  12  21  20  12  14  12  15	  #	8  ( ) * + , - . /
23  15  21  21  21  21  21  21	  #	16 0 1 2 3 4 5 6 7
20  21  12  12  24  24  24  19	  #	24 8 9 : ; < = > ?
10  22  19  19  22  16  19  24	  #	32 tmA B C D E F G
22  11  16  21  15  28  24  27	  #	40 H I J K L M N O
20  25  19  19  18  23  23  31	  #	48 P Q R S T U V W
23  19  21  21  13  35  11  21	  #	56 X Y Z       ! _
10  19  20  14  20  19  13  20	  #	64 ! a b c d e f g
19   9   9  19   9  29  19  21	  #	72 h i j k l m n o
19  19  15  15  14  18  19  27	  #	80 p q r s t u v w
20  20  17  21  17  20  15  15	  #	88 x y z     $ [ ]
22  22  22  22  29  19  16  16	  #	96 À Á Â Ã Æ Ç È É
16  16  11  11  11  11  27  27	  #	104 Ê Ë Ì Í Î Ï Ò Ó 
27  27  23  23  23  23  20  19	  #	112 Ô Ö Ù Ú Û Ü ß à
19  19  19  30  14  19  19  19	  #	120 á â ã æ ç è é ê
19   9   9   9   9  21  21  21	  #	128 ë ì í î ï ò ó ô
21  18  18  18  18  24  19  19	  #	136 ö ù ú û ü Ñ ñ ¿
20  18  19  19  21  19  19  19	  #	144 0 1 2 3 4 5 6 7
19  19  16  19  19  19  20  19	  #	152 8 9 : A B C D E
16  19  19   9  19  20  14  29	  #	160 F G H I J K L M
19  19  19  19  19  19  21  19	  #	168 N O P Q R S T U
20  32  21  19  19  19  19  19	  #	176 V W X Y Z À Á Â
19  29  19  19  19  19  19   9	  #	184 Ã Æ Ç È É Ê Ë Ì
 9   9   9  19  19  19  19  19	  #	192 Í Î Ï Ò Ó Ô Ö Ù
19  19  19  19  21  19  10   9	  #	200 Ú Û Ü ß Ñ ¿ ' .

# value for unproportional
[UNPROP]
20

# special char in subfont:
[REPLACEMENT_SPACE_CHAR]
10


# -eof- 


and this code to read the file and remove comment lines:
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
int main()
{
	FILE *file;
	file = fopen("fonts.dat", "rb");
	if (file == NULL)
		return 1;

	char readLineBuffer[200];
	
	if(readLineBuffer == NULL) { return 1; }
	if(readLineBuffer == 0) { return 1; }

	while (fgets(readLineBuffer, 200, file) != NULL)
	{
		readLineBuffer[strcspn(readLineBuffer, "\n")] = '\0';
		//if (readLineBuffer[0] == '\0' || readLineBuffer[0] == '#') {continue;}
		for(int i=0; readLineBuffer[i]!=00; i++)
		{
			if (readLineBuffer[i]=='#')
			{
				readLineBuffer[i] = 00;
				break;
			}
		}
		puts(readLineBuffer);
	}

	fclose(file);

	system("PAUSE");
	return 0;
}


how can i read values like [FONT_ID] and save them to some variable in code?
Last edited on
Think it as state machine.

You read a line.
If you have a flag set, store the line accordingly and clear the flag.
else if the line equals token, then set appropriate flag.
Could you show an example code?
bumpp, i really need this for my game.
Topic archived. No new replies allowed.