Reading from a txt file

Hello! Does anyone know why this is not working? what did I wrote wrong?
This is the txt file:
ionesc.alex@ie.ase.ro,Ionescu Alexandru,01.10.2012,120
pop.marian@cig.ase.ro,Popescu Marian,01.10.2012,134
vasilescu.geo@ie.ase.ro,Vasilescu Georgel,10.11.2013,99
ion.liviu@ie.ase.ro,Ionescu Liviu,17.11.2012,83
emil.ctin@stud.ase.ro,Emil Constantin,09.10.2011,210

Thank you!

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
  #include<iostream>

using namespace std;

struct ContMail {
	char* denumireCont;
	char* numePosesor;
	char* dataDeschidere;
	int nrMesaje;
};

void main() {
	ContMail cont;
	char denC[30];
	char buf[100];
	char prenume[50];
	char dataDesc[50];
	

	FILE* f;
	f = fopen("Conturi.txt","r");
	fscanf(f,"%s",&denC);
	while(!(feof(f))) {
		cont.denumireCont = new char[strlen(denC)+1];
		strcpy(cont.denumireCont,denC);
	
		fscanf(f,"%s %s",buf, prenume);
		strcat(buf," ");
		strcat(buf,prenume);
		strcpy(cont.numePosesor,buf);

		fscanf(f,"%s",&dataDesc);   //aici pun intr-un buffer(&dataDesc) sau in variabila mea (&cont.dataDeschidere)?
		cont.dataDeschidere = new char[strlen(dataDesc)+1];
		strcpy(cont.dataDeschidere,dataDesc);
		
		fscanf(f,"%s",&denC);
	}

}
fscanf(f,"%s",&denC); First line of file way larger that 30 symbols: buffer overflow.

strcpy(cont.numePosesor,buf); numePosesor was never initialisated: undefined behavior.
Topic archived. No new replies allowed.