I'm making a program in C with structures. It must read some text from a text file and save it into a struct. When I print the struct, I see my information with some random numbers and characters after it. Can someone help me?
#include<stdio.h>
typedef struct {
char naam[32];
int telefoon;
} Persoon;
void drukadres(Persoon*);
int main(void)
{
Persoon p;
FILE *Bestand;
Bestand = fopen("Bestand.txt", "r");
while (fread(&p,sizeof(Persoon),1,Bestand)!=NULL)
{
drukadres(&p);
}
}
void drukadres(Persoon *p)
{
printf("%s %d", p->naam,p->telefoon);
}
This is in my text file:
Vincent 0473352787
Janssens 56445343445
Thanks!