I have made a simple program in c, where i use structs, and have to read data from a file.
the program looks like this:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char ugedag[3];
int dag; char streg[3]; int month;
double klokke;
char hold1[3];
char binde1[3];
char hold2[3];
int goal1;
char bined2[3];
int goal2;
double watchers;
}Kampe;
int main(void) {
Kampe k;
FILE *kampefil;
kampefil = fopen("kampe.txt", "r");
char length[60];
int line = 0;
printf("Opgave 1\n");
while(fgets(length, 60, kampefil)){
fscanf(kampefil, "%s %d%s%d %lf %s %s %s %d %s %d %lf", k.ugedag, &k.dag, k.streg, &k.month, &k.klokke, k.hold1, k.binde1, k.hold2, &k.goal1, k.bined2, &k.goal2, &k.watchers);
if(k.goal1+k.goal2 >=7){
printf("%s %d%s%d %8.2lf %s %s %s %d %s %d %8.4lf \n", k.ugedag, k.dag, k.streg, k.month, k.klokke, k.hold1, k.binde1, k.hold2, k.goal1, k.bined2, k.goal2, k.watchers);
}
}
fclose(kampefil);
return 0;
}
and it should read a line in the text file that looks like this:
Fre 19/07 18.30 CCC - DDD 2 - 2 9.364
now the problem is that when i run the program it puts the 18 from 18.30 together with 07 from 10/07, maybe it is because i tried to first make an int that reads the 10 and then one string to read the / and at last another int to read 07, but i can't make it read it in any different way. so if you can help it would be much appriciated. And sometimes it will make an ekstra - right after AGF.