I'm a student and I have this assignment
I have a file that has 20,000 something lines, that has property and owner info
N.R.D.M CC Name, 60 caracters in total(including the spaces)Adress(same thing with the spaces here)House Number Postal Code
Equals to
"%d.%d.%d.%d %d %60c%60c%d %8c"
And the N.R.D.M works like states, city, streets and house
So there may be a few lines with the same int for states, city and streets.
/---/
I have read the file and put the categorized info into a struct array(info_geral) in an another function
typedef struct
{
int nacional;
int regional;
int distrital;
int municipal;
}id_geo;
typedef struct
{
id_geo id_geo;
long int cartao_cid;
char nome_dono[61];
char morada[61];
int num_porta;
char codigo_postal[9];
}prop_id_dono;
/---/
And I'm try that to print the fifth int(cartao_cid) and the first string(nome_dono) for a specific location.
/---/
So if I put all of the ints and don't put a 0, I will print the owner info for the property.
However if I put a 0 in the last int, in the house one, it will print all of the owners info of the street.
If I put a 0 in the street int, it will no longer ask for the house, and it will print all of the owners info of the city.
Same thing for the state, if I put a 0 in the city.
Can't do that on a national level.
/---/
Example
Input
1 1 1 1
/------/
1 1 1 0
/-----/
1 1 0
/---/
1 0
Output
The cc and name of 1.1.1.1 (One house)
/-----/
The cc and name of all of the area of 1.1.1 (All of the street)
/---/
The cc and name of all of the area of 1.1 (All of the city)
/---/
The cc and name of all of the area of 1 (All of the state)
/---/
But I'm not being able to do that and the output after a few prints, it says segmention fault(core dumped).
Here's the code
void listar_proprietarios_regiao(prop_id_dono* info_geral, int num_linhas)
{
int i;
int j;
int nacional;
int regional;
int distrital;
int municipal;
int num_prop=0;
prop_id_dono** zona_info_geral;
zona_info_geral= (prop_id_dono**) malloc(sizeof(prop_id_dono*)*num_linhas);
printf("\nId em termos nacionais:");
scanf("%d", &nacional);
if (nacional==0)
printf("Essa ação não é possível de realizar");
else
{
printf("Id em termos regionais:");
scanf("%d", ®ional);
if(regional!=0)
{
printf("Id em termos distritais:");
scanf("%d", &distrital);
if(distrital!=0)
{
printf("Id em termos municipais:");
scanf("%d", &municipal);
}
}
}
for(i=0;i<num_linhas, nacional!=0;i++)
{
for(j=0;j<num_prop;j++)
{
if(info_geral[i].id_geo.nacional==nacional)
{
if((info_geral[i].id_geo.regional==regional) && (regional!=0))
{
if((info_geral[i].id_geo.distrital==distrital) && (distrital!=0))
{
if((info_geral[i].id_geo.municipal==municipal) && (municipal!=0))
{
zona_info_geral[num_prop++]=&info_geral[i];
printf("%ld %s\n", info_geral[i].cartao_cid, info_geral[i].nome_dono);
}
else
{
zona_info_geral[num_prop++]=&info_geral[i];
printf("%ld %s\n", info_geral[i].cartao_cid, info_geral[i].nome_dono);
}
}
else
{
zona_info_geral[num_prop++]=&info_geral[i];
printf("%ld %s\n", info_geral[i].cartao_cid, info_geral[i].nome_dono);
}
}
else
{
zona_info_geral[num_prop++]=&info_geral[i];
printf("%ld %s\n", info_geral[i].cartao_cid, info_geral[i].nome_dono);
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire