problems with my function

Hello I have been writing a function in c that reads data from a file of this format:

the_dragon!
*I_will_eat_you!
*66*34*

the first line is the name of a enemy
the second is what is says to you when your near it
the third health points and the last is the level
the star is to tell my function when to read the next
thing

but when I run the function it just goes into a infinite loop on the second while loop dose anyone know why?
also the print statements are just for testing

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
void load_btl(const char* file){//not done
	FILE *fp = fopen(file, "r");
	FILE *fp2 = fopen(file, "r");
	char c;//a place holder for characters
    char caption[50] = {0};
	char name[30] = {0};
	int hp;
	int lvl;
	unsigned char i = 0;
	unsigned char data_lvl = 0;
	int integer = 0;
	char end = 0;
	
	if(fp == NULL){perror("\nFailed To Load btl File\a");getchar();return;}
	while(fscanf(fp, "%c", &c) != EOF){
	    if (c == 42/*42 is * in ASCII*/){data_lvl++;i = 0;}
		if (data_lvl == 0){name[i] = c;}
		if(data_lvl == 1){caption[i] = c;}
		i++;
	}
while (fscanf(fp2, "%i", &integer) != EOF){
	    if (integer == 42/*42 is * in ASCII*/){data_lvl++;}printf("%d", data_lvl);
		if (data_lvl == 0){/*do nothing*/}
	    if(data_lvl == 1){/*do nothing*/}
		if(data_lvl == 2){hp = integer;}
		if(data_lvl == 3){lvl = integer;}
}
printf("%i\n", hp);
printf("%i\n ", lvl);
printf("\n");
	}
Why are you reading from two copies of the same file?
At line 21, you're going to be reading from the beginning of the file.
that fixed the infinite loop but its still
not reading the data into hp and lvl
any ideas?
Last edited on
Topic archived. No new replies allowed.